pandoc-csv2table
Convert CSV to Pandoc Table Markdown
https://github.com/baig/pandoc-csv2table-filter
Version on this page: | 1.0.8 |
LTS Haskell 20.26: | 1.0.9 |
Stackage Nightly 2022-11-17: | 1.0.9 |
Latest on Hackage: | 1.0.9 |
pandoc-csv2table-1.0.8@sha256:aa3d70cf45c64a1da6ecdd867a0546c40a0e00690a049c7d62610903662cc540,1920
Module documentation for 1.0.8
Pandoc csv2table Filter
A Pandoc filter that replaces CSV content (either inside fenced code blocks or referenced CSV files) with Pandoc Table Markdown.
Installation
You can use this filter in two ways.
-
Install using Cabal: After installing Haskell platform, run:
cabal install pandoc-csv2table
-
Use the single file filter: There is a gist hosting a single file version of this filter here. Clone it and make it an executable script by running:
chmod +x pandoc-csv2table.hs
You can also use this filter in your Pandoc application by calling
tablifyCsvlinks
.
Usage
Referencing or including CSV
There are three ways to include CSV in your markdown.
-
Referencing CSV file in Image Links:
![This text will become the table caption](table.csv)
-
Referencing CSV file in Fenced Code Blocks:
```{.table caption="This is the **caption**" source="table.csv"} ```
Only code blocks having
.table
class will be processed. -
Including CSV content inside Fenced Code Blocks:
```{.table aligns="LCR" caption="This is the **caption**" header="yes"} Fruit, Quantity, Price apples, 15, 3.24 oranges, 12, 2.22 ```
Only code blocks having
.table
class will be processed.
CSV file or content can contain pandoc markdown. It will be parsed by the Pandoc Markdown Reader before being inserted as a table into the document.
Running the filter
Given the filename test.md
, run the filter using command
pandoc --filter pandoc-csv2table -o test.html test.md
or
pandoc -t json test.md | pandoc-csv2table | pandoc -f json -o test.html
Examples
See example.md and the rendered pdf version in the Examples folder for more details on usage.
Options
You can specify a configuration string for image links and attributes for fenced code blocks. There are valid options for specifying
- Type of the table
- Column alignments
- Whether to treat the first line of the CSV file as header or not
Configuration String
It is included right before the closing square bracket without any space in between, as shown in the example below.
![Another table. mylrcd](table.csv)
mylrcd
is the configuration string.
This will be rendered as a multiline table with a header with first column
left-aligned, second right-aligned, third center-aligned, and the
fourth one having default alignment.
The config string will be removed from the caption after being processed.
The config string can contain following letters:
s
for simple tablem
for multiline tableg
for grid tablep
for pipe tabley
(from yes) when you want the first row of CSV file to be the header.n
(from no) when you want to omit the header.l
for left alignment of the columnr
for right alignment of the columnc
for ccenter alignment of the columnd
for default alignment of the column
You can specify l
r
c
d
for each column in a series.
The extra letters will be ignored if they exceed the number of columns in the
CSV file.
Attributes
You can specify header attributes in fecnced code blocks like this:
```{.table type="pipe" aligns="LCR" caption="A **caption**" header="yes"}
Fruit, Quantity, Price
apples, 15, 3.24
oranges, 12, 2.22
```
Note: .table
must be included if the fenced code block is intended to be
processed by this filter.
Valid attributes that you can specify in code blocks include:
- type of the table can be
simple
,multiline
,grid
(default), orpipe
. - header can be
yes
(default) orno
- caption is a string which can contain markdown.
- source is the path to a valid CSV file to be rendered as pandoc table. If present, the contents inside the fenced code blocks are ignored.
- aligns specify alignment for each column. Use
L
for left,R
for right,C
for center, andD
for default.
License
Copyright © 2015-2020 Wasif Hasan Baig,Venkateswara Rao Mandela
Source code is released under the Terms and Conditions of MIT License.
Please refer to the License file in the project’s root directory.
Changes
Change Log
All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning and Haskell package versioning policy.
Unreleased
1.0.8 - 2020-01-27
- update stack version
- Fix build failure with pandoc 1.17
- Fix build failure with pandoc 2.9
1.0.7 - 2019-06-02
- Export
tablifyCSVLinksPure
for cases where no IO is required. - Handle change in Pandoc markdown reader default options in pandoc-csv2table See https://github.com/jgm/pandoc/commit/a58369a7e65075800
- Update stack version
1.0.6 - 2018-11-29
- Made compatibile with Pandoc 2.0+ (Merged pull request by @vmandela)
- Updated cabal file
- Updated stack version
1.0.5 - 2017-05-05
1.0.4 - 2016-02-07
Changed
- Exporting
tablifyCsvLinks
function (Merged pull request by @vmandela)
Added
- Added
stack.yaml
.
[1.0.3] - 2016-02-07
Changed
- Updated cabal file
Fixed
- Handling
tablifyCsvLinks
conditionally using CPP macro (fixes issue #17).
1.0.1 - 2015-06-02
Fixed
- Now handling
readMarkdown
conditionally using CPP macro (fixes issue #8).
1.0.0
- The first release.