For those who are interested in using CSV tables in pandoc markdown, I’m writing a filter that build upon one of panflute’s example. And I’m still thinking about which exact syntax to use. Feel free to give suggestions.
What separate this to existing filters is the automatic calculation of the column-width (in contrast with pandoc-placetable) and write to pandoc AST directly (in contrast with pandoc-csv2table), as well as specifying the table width (a ratio to the line-width). And comparing with the 2 said filters, panflute’s example use YAML to store data, rather than the attributes of the code-block (which I think is more natural for data).
There’s a notebook in ickc/pandoc-table-csv-test/panflute-csv2table.ipynb and the the filter is at ickc/pandoc-table-csv-test/csv-tables.py.
The current syntax is this (borrow much from panflute’s example, and the csv is borrowed from pandoc-csv2table):
~~~csv
title: "*Great* Title"
has-header: False
column-width:
- 0.1
- 0.2
- 0.3
- 0.4
table-width: 0.8
alignment: LRC
markdown: True
---
1,2,3,4
~~~
My biggest questions is which metadata keys to use. Backward-compatibility-wise, since pandoc-csv2table and pandoc-placetable use attributes to store metadata, while panflute’s example and mine use YAML to store, the only one I need to consider backward-compatibility is panflute’s. But I actually think pandoc-csv2table/placetable’s keys make more sense. e.g. header
vs has-header
, caption
vs title
.
And for alignment, pandoc-csv2table/placetable use aligns. For width, placetable use widths. I’m not sure if I should follow them.
A comparison of the keys: (The output is generated by my filter)
+--------+----------------------------+-------------------+--------------------+--------------------------+
| | pandoc-csv2table | pandoc-placetable | panflute example | my proposal |
+========+============================+===================+====================+==========================+
| type | type=simple|multiline|grid | | | |
| | |pipe | | | |
+--------+----------------------------+-------------------+--------------------+--------------------------+
| header | header=yes|no | header=yes|no | has-header: | header: True|False |
| | | | True|False | |
+--------+----------------------------+-------------------+--------------------+--------------------------+
| captio | caption | caption | title | caption |
| n | | | | |
+--------+----------------------------+-------------------+--------------------+--------------------------+
| source | source | file | source | source |
+--------+----------------------------+-------------------+--------------------+--------------------------+
| aligns | aligns=LRCD | aligns=LRCD | | alignment: LRCD |
+--------+----------------------------+-------------------+--------------------+--------------------------+
| width | | widths="0.5 0.2 | | column-width: \[0.5, |
| | | 0.3" | | 0.2, 0.3\] |
+--------+----------------------------+-------------------+--------------------+--------------------------+
| | | inlinemarkdown | | markdown: True|False |
+--------+----------------------------+-------------------+--------------------+--------------------------+
| | | delimiter | | |
+--------+----------------------------+-------------------+--------------------+--------------------------+
| | | quotechar | | |
+--------+----------------------------+-------------------+--------------------+--------------------------+
| | | id (wrapped by | | |
| | | div) | | |
+--------+----------------------------+-------------------+--------------------+--------------------------+