Idempotent in this case means pantable
and pantable2csv
are “inverse” to each other. e.g. pandoc -t markdown -F pantable -F pantable2csv test.md
should be identical to test.md
. This can be done because pantable2csv
losslessly represents all info in the pandoc’s AST into YAML+CSV in code-block. The only cases it ain’t lossless are
when pandoc parses the markdown in each cell to AST, and pantable2csv passes those AST back into markdown by using pandoc. i.e. whether this is idempotent or not depends on pandoc’s markdown -> AST -> markdown
conversion.
Potentially the width might have some truncation error, especially when the to-format and from-format are not the same.
When I say I achieve , it means that pandoc -t native -F pantable -F pantable2csv -F pantable -F pantable2csv -F pantable -F pantable2csv csv_table.md
= pandoc -t native -F pantable -F pantable2csv -F pantable -F pantable2csv csv_table.md
(which is part of the unit test). The diff between and is exactly from (1).
A corollary to (1) is that it is kind of slow, since each table cells call pandoc for the conversion once. Probably nothing can be improved except to reinvent the parsing of tables (probably there’s no way to tell pandoc to ignore markdown in cell, while not escaping character sequences). (And tables has cells so inherently it will be slow.) But I don’t quite worry about the performance aspect if it is going to solve a workflow problem.
Eventually I think I’m going to make a thin wrapper of both to provide a cli version. And then automator scripts can be created. Then basically I can select the table in text editors and call system services to convert it in place. i.e. highlight table, convert to csv, edit, highlight and convert to table. This system-service-part won’t be cross-platform though. (By the way, a sad news is Apple just fired the one responsible for Automator and Applescripts, and kill the whole team! This used be the forte of OS X!)
In a sense, pantable2csv
gives one the power to edit the table “in AST directly” easily, while pantable
provide a way to pretty-print it back in native markdown. Note that after commit 298e6f3, all pandoc table’s info has a markdown representation (grid_tables only misses alignment which is added in that commit).