Giter Club home page Giter Club logo

pandoc-csv2table's Introduction

Pandoc csv2table Filter

Build Status

A Pandoc filter that replaces CSV content (either inside fenced code blocks or referenced CSV files) with Pandoc Table Markdown.

A CSV file rendered to Markdown and PDF

Installation

You can use this filter in two ways.

  1. Install using Cabal: After installing Haskell platform, run:

    cabal install pandoc-csv2table
    
  2. 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.

  1. Referencing CSV file in Image Links:

    ![This text will become the table caption](table.csv)
    
  2. 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.

  3. 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 table
  • m for multiline table
  • g for grid table
  • p for pipe table
  • y (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 column
  • r for right alignment of the column
  • c for ccenter alignment of the column
  • d 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), or pipe.
  • header can be yes (default) or no
  • 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, and D for default.

License

Copyright © 2015-2023 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.

pandoc-csv2table's People

Contributors

baig avatar pacien avatar vmandela avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pandoc-csv2table's Issues

Windows table to pipe style markdown

Hello
I have a problem to convert a csv to markdown.
I have an escape character and a no new line for the table lines.

image

Is it a problem related to windows?

My configurations:
Windows 10, conda conda 4.5.11
stack install pandoc-csv2table
pandoc 2.5

Couldn't match type ‘Data.Text.Internal.Text’ with ‘[Char]’ Expected type: String

Failed to build pandoc-csv2table-1.0.7.
Build log (
/Users/mohideennoordeen/.cabal/logs/ghc-8.8.1/pndc-csv2tbl-1.0.7-e0b3c5e1.log
):
Configuring library for pandoc-csv2table-1.0.7..
Preprocessing library for pandoc-csv2table-1.0.7..
Building library for pandoc-csv2table-1.0.7..
[1 of 4] Compiling Text.Table.Definition ( src/Text/Table/Definition.hs, dist/build/Text/Table/Definition.o )
[2 of 4] Compiling Text.Table.Builder ( src/Text/Table/Builder.hs, dist/build/Text/Table/Builder.o )
[3 of 4] Compiling Text.Table.Helper ( src/Text/Table/Helper.hs, dist/build/Text/Table/Helper.o )

src/Text/Table/Helper.hs:94:44: error:
• Couldn't match type ‘Data.Text.Internal.Text’ with ‘[Char]’
Expected type: String
Actual type: Data.Text.Internal.Text
• In the first argument of ‘toTableType1’, namely ‘s’
In the expression: toTableType1 s
In an equation for ‘getTableType’:
getTableType ((J.Str s) : []) = toTableType1 s

install error: Couldn't match type ‘Either Text.Pandoc.Error.PandocError J.Pandoc’ with ‘J.Pandoc’

I'm trying to install this alongside the latest pandoc but I am hitting this error. GHC version 7.10.1,

Configuring pandoc-csv2table-1.0.0...
Building pandoc-csv2table-1.0.0...
Failed to install pandoc-csv2table-1.0.0
Build log ( /Users/cole/.cabal/logs/pandoc-csv2table-1.0.0.log ):
Configuring pandoc-csv2table-1.0.0...
Building pandoc-csv2table-1.0.0...
Preprocessing library pandoc-csv2table-1.0.0...
[1 of 3] Compiling Text.Table.Definition ( src/Text/Table/Definition.hs, dist/build/Text/Table/Definition.o )
[2 of 3] Compiling Text.Table.Builder ( src/Text/Table/Builder.hs, dist/build/Text/Table/Builder.o )
[3 of 3] Compiling Text.Table.Helper ( src/Text/Table/Helper.hs, dist/build/Text/Table/Helper.o )

src/Text/Table/Helper.hs:136:26:
    Couldn't match type ‘Either Text.Pandoc.Error.PandocError J.Pandoc’
                   with ‘J.Pandoc’
    Expected type: String -> J.Pandoc
      Actual type: String
                   -> Either Text.Pandoc.Error.PandocError J.Pandoc
    In the first argument of ‘(.)’, namely ‘readMarkdown def’
    In the second argument of ‘(.)’, namely
      ‘readMarkdown def
       . toMarkdown (getTableType l) AfterTable
         . mkTable "" (getAligns l) (isHeaderPresent l)’

src/Text/Table/Helper.hs:142:25:
    Couldn't match type ‘Either Text.Pandoc.Error.PandocError J.Pandoc’
                   with ‘J.Pandoc’
    Expected type: String -> J.Pandoc
      Actual type: String
                   -> Either Text.Pandoc.Error.PandocError J.Pandoc
    In the first argument of ‘(.)’, namely ‘readMarkdown def’
    In the expression:
      readMarkdown def
      . toMarkdown (toTableType $ getAtr "type" as) AfterTable
        . mkTable
            (getAtr "caption" as)
            (toAlign $ getAtr "aligns" as)
            (isHeaderPresent1 $ getAtr "header" as)
cabal: Error: some packages failed to install:
pandoc-csv2table-1.0.0 failed during the building phase. The exception was:
ExitFailure 1

trouble installing

Hi.

I tried to install this filter using cabal, and got this:

Building pandoc-csv2table-1.0.0...
Preprocessing library pandoc-csv2table-1.0.0...
[1 of 3] Compiling Text.Table.Definition ( src/Text/Table/Definition.hs, dist/build/Text/Table/Definition.o )
[2 of 3] Compiling Text.Table.Builder ( src/Text/Table/Builder.hs, dist/build/Text/Table/Builder.o )
[3 of 3] Compiling Text.Table.Helper ( src/Text/Table/Helper.hs, dist/build/Text/Table/Helper.o )

src/Text/Table/Helper.hs:136:26:
    Couldn't match type ‘Either Text.Pandoc.Error.PandocError J.Pandoc’
                  with ‘J.Pandoc’
    Expected type: String -> J.Pandoc
      Actual type: String
                   -> Either Text.Pandoc.Error.PandocError J.Pandoc
    In the first argument of ‘(.)’, namely ‘readMarkdown def’
    In the second argument of ‘(.)’, namely
      ‘readMarkdown def
       . toMarkdown (getTableType l) AfterTable
         . mkTable "" (getAligns l) (isHeaderPresent l)’

src/Text/Table/Helper.hs:142:25:
    Couldn't match type ‘Either Text.Pandoc.Error.PandocError J.Pandoc’
                  with ‘J.Pandoc’
    Expected type: String -> J.Pandoc
      Actual type: String
                   -> Either Text.Pandoc.Error.PandocError J.Pandoc
    In the first argument of ‘(.)’, namely ‘readMarkdown def’
    In the expression:
      readMarkdown def
      . toMarkdown (toTableType $ getAtr "type" as) AfterTable
        . mkTable
            (getAtr "caption" as)
            (toAlign $ getAtr "aligns" as)
            (isHeaderPresent1 $ getAtr "header" as)
cabal: Error: some packages failed to install:
pandoc-csv2table-1.0.0 failed during the building phase. The exception was:
ExitFailure 1

I have a working pandoc install, from this version: https://github.com/jgm/pandoc/tree/f5087d84a19380bb08cdcba365cc9fadff9adc41 (It's less than two weeks old.)

Do you have any idea what's wrong?

Thank you.

[Bug] `type="pipe"` does not work at all; `type="multiline"` does not honor `aligns="L"`

Consider the following Markdown:

$ cat csvtables.md | gsed "s#^#    #"


# Simple Tables

```` {.table caption="Does this result in a `simple_table`?" type="simple" aligns="RCRLCRC" header="yes"}
**Fruit(R)**, *Quantity(C)*, ***Price(R)***, **`Origin`(L)**, `Quality`(C), packed(R), sold-out?(C)
apples, 15,"3,24", Spain, excellent, ***yes***, yes 
oranges, 12,"2,22", Germany, **sour**, no, soon 
````

```` {.table caption="Does this result in a `simple_table`?" type="simple" aligns="RCRLCRC" header="no"}
**Fruit(R)**, *Quantity(C)*, ***Price(R)***, **`Origin`(L)**, `Quality`(C), packed(R), sold-out?(C)
apples, 15,"3,24", Spain, excellent, ***yes***, yes 
oranges, 12,"2,22", Germany, **sour**, no, soon 
````

# Grid Tables

```` {.table caption="Does this result in a `grid_table`?" type="grid" aligns="RCRLCRC" header="yes"}
**Fruit(R)**, *Quantity(C)*, ***Price(R)***, **`Origin`(L)**, `Quality`(C), packed(R), sold-out?(C)
apples, 15,"3,24", Spain, excellent, ***yes***, yes 
oranges, 12,"2,22", Germany, **sour**, no, soon 
````

```` {.table caption="Does this result in a `grid_table`?" type="grid" aligns="RCRLCRC" header="no"}
**Fruit(R)**, *Quantity(C)*, ***Price(R)***, **`Origin`(L)**, `Quality`(C), packed(R), sold-out?(C)
apples, 15,"3,24", Spain, excellent, ***yes***, yes 
oranges, 12,"2,22", Germany, **sour**, no, soon 
````

# Pipe Tables

```` {.table caption="Does this result in a `pipe_table`?" type="pipe" aligns="RCRLCRC" header="yes"}
**Fruit(R)**, *Quantity(C)*, ***Price(R)***, **`Origin`(L)**, `Quality`(C), packed(R), sold-out?(C)
apples, 15,"3,24", Spain, excellent, ***yes***, yes 
oranges, 12,"2,22", Germany, **sour**, no, soon 
````

```` {.table caption="Does this result in a `pipe_table`?" type="pipe" aligns="RCRLCRC" header="no"}
**Fruit(R)**, *Quantity(C)*, ***Price(R)***, **`Origin`(L)**, `Quality`(C), packed(R), sold-out?(C)
apples, 15,"3,24", Spain, excellent, ***yes***, yes 
oranges, 12,"2,22", Germany, **sour**, no, soon 
````

# Multiline Tables

```` {.table caption="Does this result in a `multiline_table`?" type="multiline" aligns="RCRLCRC" header="yes"}
**Fruit(R)**, *Quantity(C)*, ***Price(R)***, **`Origin`(L)**, `Quality`(C), packed(R), sold-out?(C)
apples, 15,"3,24", Spain, excellent, ***yes***, yes 
oranges, 12,"2,22", Germany, **sour**, no, soon 
````

```` {.table caption="Does this result in a `multiline_table`?" type="multiline" aligns="RCRLCRC" header="no"}
**Fruit(R)**, *Quantity(C)*, ***Price(R)***, **`Origin`(L)**, `Quality`(C), packed(R), sold-out?(C)
apples, 15,"3,24", Spain, excellent, ***yes***, yes 
oranges, 12,"2,22", Germany, **sour**, no, soon 
````

Running this Pandoc command: pandoc -f markdown --filter=pandoc-csv2table -t markdown csvtables.md results in the following output:

Simple Tables
=============

    **Fruit(R)**  *Quantity(C)*    ***Price(R)***  **`Origin`(L)**   `Quality`(C)    packed(R)  sold-out?(C)
  -------------- --------------- ---------------- ----------------- -------------- ----------- --------------
          apples       15                    3,24       Spain         excellent      ***yes***      yes
         oranges       12                    2,22      Germany         **sour**             no      soon

  : Does this result in a `simple_table`?

  -------------- --------------- ---------------- ----------------- -------------- ----------- --------------
    **Fruit(R)**  *Quantity(C)*    ***Price(R)***  **`Origin`(L)**   `Quality`(C)    packed(R)  sold-out?(C)
          apples       15                    3,24       Spain         excellent      ***yes***      yes
         oranges       12                    2,22      Germany         **sour**             no      soon
  -------------- --------------- ---------------- ----------------- -------------- ----------- --------------

  : Does this result in a `simple_table`?

Grid Tables
===========

+-----------+------------+-------------+-------------+------------+----------+------------+
| **Fruit(R | *Quantity( | ***Price(R) | **`Origin`( | `Quality`( | packed(R | sold-out?( |
| )**       | C)*        | ***         | L)**        | C)         | )        | C)         |
+===========+============+=============+=============+============+==========+============+
| apples    | 15         | 3,24        | Spain       | excellent  | ***yes** | yes        |
|           |            |             |             |            | *        |            |
+-----------+------------+-------------+-------------+------------+----------+------------+
| oranges   | 12         | 2,22        | Germany     | **sour**   | no       | soon       |
+-----------+------------+-------------+-------------+------------+----------+------------+

: Does this result in a `grid_table`?

+-----------+------------+-------------+-------------+------------+----------+------------+
| **Fruit(R | *Quantity( | ***Price(R) | **`Origin`( | `Quality`( | packed(R | sold-out?( |
| )**       | C)*        | ***         | L)**        | C)         | )        | C)         |
+-----------+------------+-------------+-------------+------------+----------+------------+
| apples    | 15         | 3,24        | Spain       | excellent  | ***yes** | yes        |
|           |            |             |             |            | *        |            |
+-----------+------------+-------------+-------------+------------+----------+------------+
| oranges   | 12         | 2,22        | Germany     | **sour**   | no       | soon       |
+-----------+------------+-------------+-------------+------------+----------+------------+

: Does this result in a `grid_table`?

Pipe Tables
===========

    **Fruit(R)**  *Quantity(C)*    ***Price(R)*** **`Origin`(L)**    `Quality`(C)    packed(R)  sold-out?(C)
  -------------- --------------- ---------------- ----------------- -------------- ----------- --------------
          apples       15                    3,24 Spain               excellent      ***yes***      yes
         oranges       12                    2,22 Germany              **sour**             no      soon

  : Does this result in a `pipe_table`?

|---------------:|:----------------:|------------------:|:-------------------|:---------------:|-------------:|:---------------:|
| **Fruit(R)** | *Quantity(C)* | ***Price(R)*** | **`Origin`(L)** |
`Quality`(C) | packed(R) | sold-out?(C) | | apples | 15 | 3,24 | Spain |
excellent | ***yes*** | yes | | oranges | 12 | 2,22 | Germany | **sour**
| no | soon |

Table: Does this result in a `pipe_table`?

Multiline Tables
================

  ---------------------------------------------------------------------------
  **Fruit(R *Quantity( ***Price(R) **`Origin`(L `Quality`( packed(R sold-out?
        )**    C)*             ***     )**          C)            )    (C)
  --------- ---------- ----------- ------------ ---------- -------- ---------
     apples     15            3,24    Spain     excellent  ***yes**    yes
                                                                  * 

    oranges     12            2,22   Germany     **sour**        no   soon
  ---------------------------------------------------------------------------

  : Does this result in a `multiline_table`?

  --------- ---------- ----------- ------------ ---------- -------- ---------
  **Fruit(R *Quantity( ***Price(R) **`Origin`(L `Quality`( packed(R sold-out?
        )**    C)*             ***     )**          C)            )    (C)

     apples     15            3,24    Spain     excellent  ***yes**    yes
                                                                  * 

    oranges     12            2,22   Germany     **sour**        no   soon
  --------- ---------- ----------- ------------ ---------- -------- ---------

  : Does this result in a `multiline_table`?

Running this Pandoc command: pandoc -f markdown --filter=pandoc-csv2table -o csvtables.pdf csvtables.md -V geometry:"margin=0.5cm, paperwidth=595pt, paperheight=35cm" results in this PDF (screenshot):

PDF output

So for the case of type="pipe" two things do not work:

  • if there is a header="yes" a table is generated. However, it is not a pipe_table, but a simple_table
  • if there is a header="no", the table looks like there was an attempt to indeed create a pipe_table, but the output is b0rken.

For the case of type="multiline" one thing doesn't work as expected:

  • column no. 4 ("Origin(L)") is not left-aligned, but centered.

BTW, if I replace my above ````` {.table ....} fences by ````{.table ....} fences (3 backticks, no blank before the curly brace), then the `multiline_table` output is missing the blank lines in between table rows. Though I'm currently not sure if that syntax violates the spec or if it is "legal"...


Observations about the line lengths...

Also, the grid_table output looks a bit funny with the line-breaks within all the header and some of the table body cells. It seems to be "legal", though.

But this is not required, since the longest line of the Markdown output {the b0rken pipe_table separator line (for header="no") with the colons} is using 130 characters, while the grid_table is using only 92.

Adding --columns=110 to the Pandoc command line to produce Markdown tables, results in...

  • ...the following (better) grid_table output, which does not apply line-breaks within cells;
  • ...the following (worse) multiline_table output, which does no longer contain the blank lines in between table rows. (However, this may mean that these blank lines are only really required _IF_ indeed there is a "multiline" used for any one cell. Since the 110 column width for the Markdown output does grant enough space for all cell contents of the given table to fit 1 line, it may be superfluous...)
Grid Tables
===========

+----------------+------------------+-------------------+--------------------+-----------------+--------------+-----------------+
| **Fruit(R)**   | *Quantity(C)*    | ***Price(R)***    | **`Origin`(L)**    | `Quality`(C)    | packed(R)    | sold-out?(C)    |
+================+==================+===================+====================+=================+==============+=================+
| apples         | 15               | 3,24              | Spain              | excellent       | ***yes***    | yes             |
+----------------+------------------+-------------------+--------------------+-----------------+--------------+-----------------+
| oranges        | 12               | 2,22              | Germany            | **sour**        | no           | soon            |
+----------------+------------------+-------------------+--------------------+-----------------+--------------+-----------------+

: Does this result in a `grid_table`?

+----------------+------------------+-------------------+--------------------+-----------------+--------------+-----------------+
| **Fruit(R)**   | *Quantity(C)*    | ***Price(R)***    | **`Origin`(L)**    | `Quality`(C)    | packed(R)    | sold-out?(C)    |
+----------------+------------------+-------------------+--------------------+-----------------+--------------+-----------------+
| apples         | 15               | 3,24              | Spain              | excellent       | ***yes***    | yes             |
+----------------+------------------+-------------------+--------------------+-----------------+--------------+-----------------+
| oranges        | 12               | 2,22              | Germany            | **sour**        | no           | soon            |
+----------------+------------------+-------------------+--------------------+-----------------+--------------+-----------------+

: Does this result in a `grid_table`?

[....]

Multiline Tables
================

    **Fruit(R)**  *Quantity(C)*      ***Price(R)***  **`Origin`(L)**    `Quality`(C)      packed(R)  sold-out?(C)
  -------------- ---------------- ----------------- ------------------ --------------- ------------ --------------
          apples        15                     3,24       Spain           excellent       ***yes***      yes
         oranges        12                     2,22      Germany          **sour**               no      soon

  : Does this result in a `multiline_table`?

  -------------- ---------------- ----------------- ------------------ --------------- ------------ --------------
    **Fruit(R)**  *Quantity(C)*      ***Price(R)***  **`Origin`(L)**    `Quality`(C)      packed(R)  sold-out?(C)
          apples        15                     3,24       Spain           excellent       ***yes***      yes
         oranges        12                     2,22      Germany          **sour**               no      soon
  -------------- ---------------- ----------------- ------------------ --------------- ------------ --------------

  : Does this result in a `multiline_table`?

pandoc-csv2table-1.0.7 build failure with pandoc-2.9.1.1

As seen on the Stackage build server, a number of type errors such as this:

    /var/stackage/work/unpack-dir/unpacked/pandoc-csv2table-1.0.7-5358bfaf1271
96a3e4b899e6b67903d8176754bfcaca579856b8072fd04d9c7e/src/Text/Table/Helper.hs:
123:36: error:
        • Couldn't match type ‘Data.Text.Internal.Text’ with ‘[Char]’
          Expected type: String
            Actual type: Data.Text.Internal.Text
        • In the first argument of ‘toAlign’, namely ‘s’
          In the expression: toAlign s
          In an equation for ‘getAligns’:
              getAligns ((J.Str s) : []) = toAlign s
        |
    123 | getAligns ((J.Str s):[]) = toAlign s
        |

[Feature request] Allow headers to be defined in fenced block

  • Allow the table header line to be defined inside the fenced code block. For example by supporting an additional options for the header attribute: header="fenced" and header="line 13".

This is useful (also in combination with my other feature requests) when you have rather large CSV files, but you do not want to change the headers (permanently or temporarily) just for the table inclusion in a Markdown/Pandoc document. (Some headers are fine for processing/maintaining the CSV table in a spreadsheet, but may not be good in their original version in a published document.)

cabal-3.10.3.0.exe: Failed to build old-time-1.1.0.4

Error: cabal-3.10.3.0.exe: Failed to build old-time-1.1.0.4 (which is required
by exe:pandoc-csv2table from pandoc-csv2table-1.0.9). The failure occurred
during the configure step. The build process terminated with exit code 127

I have Cygwin installed, I don't know what is happening here...

Thanks!

Dependancy on pandoc

Is there a reason for the dependency on pandoc? The idea for filters is to depend on pandoc-types so that they don't have such a large dependency footprint.

Incompatible with Pandoc 2.0+

Pandoc introduced a breaking API change for versions 2.0+ in commit 94b3dac -- readers now take Text instead of String. As a result, the filter can no longer be installed using Cabal.

The specific build error is:

src/Text/Table/Helper.hs:153:47: error:
    • Couldn't match type ‘[Char]’ with ‘Data.Text.Internal.Text’
      Expected type: Data.Text.Internal.Text
        Actual type: String
    • In the second argument of ‘readMarkdown’, namely ‘s’
      In the expression: readMarkdown o s
      In an equation for ‘read’: read = readMarkdown o s

It looks like one of the following would need to be updated:

pandoc >= 1.13.0.0,

readMarkdown' :: ReaderOptions -> String -> J.Pandoc
readMarkdown' o s = case read of
(Left _) -> J.Pandoc J.nullMeta []
(Right p) -> p
where read = readMarkdown o s

[Bug] Values which contain commas are not processed correctly (no workaround found)

Consider this CSV file:

**Fruit**, *Quantity*, ***Price***, **`Origin`**, `Quality`, packed, sold-out?
apples, 15, "3,24", Spain, excellent, ***yes***, yes 
oranges, 12, "2,22", Germany, **sour**, no, soon

This uses a comma as a decimal separator for currency (and other numbers), as is common in Germany. Normally you would escape that comma by quoting the complete value, as seen above, and Excel or other CSV processing applications would have no problem with it.

The filter is unable to output anything from this input.

If I escape the commas with a backslash, then this filter's output is however somewhat broken:

$ pandoc my2.md  --filter=pandoc-csv2table --to=markdown --columns=80
+------------+-------------+--------------+---------------+------------+------------+------------+
| **Fruit**  | *Quantity*  | ***Price***  | **`Origin`**  | `Quality`  | packed     | sold-out?  |
+============+=============+==============+===============+============+============+============+
| apples     | 15          | 3\           | 24            | Spain      | excellent  | ***yes***  |
|            |             |              |               |            |            | | yes      |
+------------+-------------+--------------+---------------+------------+------------+------------+
| oranges    | 12          | 2\           | 22            | Germany    | **sour**   | no | soon  |
+------------+-------------+--------------+---------------+------------+------------+------------+

: This is the **caption**

pandoc-csv2table does not install with cabal 1.22.4.0 (1.22.2.0 cabal library)

kp@aa196:> cabal update
[...]

kp@aa196:> cabal install cabal-install
[....]

kp@aa196:> cabal install pandoc-csv2table 
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: pandoc-csv2table-1.0.0 (user goal)
next goal: base (dependency of pandoc-csv2table-1.0.0)
rejecting: base-4.7.0.1/installed-df2... (conflict: pandoc-csv2table =>
base>=4.8 && <4.9)
rejecting: base-4.8.0.0, 4.7.0.2, 4.7.0.1, 4.7.0.0, 4.6.0.1, 4.6.0.0, 4.5.1.0,
4.5.0.0, 4.4.1.0, 4.4.0.0, 4.3.1.0, 4.3.0.0, 4.2.0.2, 4.2.0.1, 4.2.0.0,
4.1.0.0, 4.0.0.0, 3.0.3.2, 3.0.3.1 (global constraint requires installed instance)
Dependency tree exhaustively searched.

kp@1a196:> cabal --version
cabal-install version 1.22.4.0
using version 1.22.2.0 of the Cabal library

Pandoc "Couldn't match type ‘m0 J.Pandoc’ with ‘J.Pandoc’"

Trying to use Pandoc the first time. I've gone through

I'm trying to convert the simple file and getting the following error:

~ $ cat simple.csv
a,b
aa,bb
~ $ pandoc --filter ./csv2table/csv2table.hs simple.csv 

csv2table/csv2table.hs:406:26: error:
    • Couldn't match type ‘m0 J.Pandoc’ with ‘J.Pandoc’
      Expected type: [Lines] -> J.Pandoc
        Actual type: [Lines] -> m0 J.Pandoc
    • In the second argument of ‘(.)’, namely
        ‘readMarkdown def
           . toMarkdown (getTableType l) AfterTable
               . mkTable "" (getAligns l) (isHeaderPresent l)’
      In the expression:
        addInlineLabel (removeConfigString l)
          . readMarkdown def
              . toMarkdown (getTableType l) AfterTable
                  . mkTable "" (getAligns l) (isHeaderPresent l)
      In an equation for ‘tableFromImageInline’:
          tableFromImageInline l
            = addInlineLabel (removeConfigString l)
                . readMarkdown def
                    . toMarkdown (getTableType l) AfterTable
                        . mkTable "" (getAligns l) (isHeaderPresent l)
    |
406 |                          readMarkdown def .
    |                          ^^^^^^^^^^^^^^^^^^...

csv2table/csv2table.hs:407:26: error:
    • Couldn't match type ‘[Char]’ with ‘Data.Text.Internal.Text’
      Expected type: [Lines] -> Data.Text.Internal.Text
        Actual type: [Lines] -> String
    • In the second argument of ‘(.)’, namely
        ‘toMarkdown (getTableType l) AfterTable
           . mkTable "" (getAligns l) (isHeaderPresent l)’
      In the second argument of ‘(.)’, namely
        ‘readMarkdown def
           . toMarkdown (getTableType l) AfterTable
               . mkTable "" (getAligns l) (isHeaderPresent l)’
      In the expression:
        addInlineLabel (removeConfigString l)
          . readMarkdown def
              . toMarkdown (getTableType l) AfterTable
                  . mkTable "" (getAligns l) (isHeaderPresent l)
    |
407 |                          toMarkdown (getTableType l) AfterTable .
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

csv2table/csv2table.hs:412:25: error:
    • Couldn't match type ‘m1 J.Pandoc’ with ‘J.Pandoc’
      Expected type: CSV -> J.Pandoc
        Actual type: [Lines] -> m1 J.Pandoc
    • In the expression:
        readMarkdown def
          . toMarkdown (toTableType $ getAtr "type" as) AfterTable
              . mkTable
                  (getAtr "caption" as)
                  (toAlign $ getAtr "aligns" as)
                  (isHeaderPresent1 $ getAtr "header" as)
      In an equation for ‘tableFromCodeBlock’:
          tableFromCodeBlock as
            = readMarkdown def
                . toMarkdown (toTableType $ getAtr "type" as) AfterTable
                    . mkTable
                        (getAtr "caption" as)
                        (toAlign $ getAtr "aligns" as)
                        (isHeaderPresent1 $ getAtr "header" as)
    |
412 | tableFromCodeBlock as = readMarkdown def .
    |                         ^^^^^^^^^^^^^^^^^^...

csv2table/csv2table.hs:413:25: error:
    • Couldn't match type ‘[Char]’ with ‘Data.Text.Internal.Text’
      Expected type: [Lines] -> Data.Text.Internal.Text
        Actual type: [Lines] -> String
    • In the second argument of ‘(.)’, namely
        ‘toMarkdown (toTableType $ getAtr "type" as) AfterTable
           . mkTable
               (getAtr "caption" as)
               (toAlign $ getAtr "aligns" as)
               (isHeaderPresent1 $ getAtr "header" as)’
      In the expression:
        readMarkdown def
          . toMarkdown (toTableType $ getAtr "type" as) AfterTable
              . mkTable
                  (getAtr "caption" as)
                  (toAlign $ getAtr "aligns" as)
                  (isHeaderPresent1 $ getAtr "header" as)
      In an equation for ‘tableFromCodeBlock’:
          tableFromCodeBlock as
            = readMarkdown def
                . toMarkdown (toTableType $ getAtr "type" as) AfterTable
                    . mkTable
                        (getAtr "caption" as)
                        (toAlign $ getAtr "aligns" as)
                        (isHeaderPresent1 $ getAtr "header" as)
    |
413 |                         toMarkdown (toTableType $ getAtr "type" as) AfterTable .
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

csv2table/csv2table.hs:424:27: error:
    • The constructor ‘J.Image’ should have 3 arguments, but has been given 2
    • In the pattern: J.Image l (f, _)
      In the pattern: [(J.Image l (f, _))]
      In the pattern: J.Para [(J.Image l (f, _))]
    |
424 | tablifyCsvLinks (J.Para [(J.Image l (f, _))]) | "csv" `isSuffixOf` f = do
    |   
                      ^^^^^^^^^^^^^^^^

I've installed pandoc and pandoc-types through cabal. However, I cannot specify the filter without giving the explicit .hs and path. Everything should be up to date.

~$: pandoc --version
pandoc 2.5
Compiled with pandoc-types 1.17.5.4, texmath 0.11.1.2, skylighting 0.7.4

pandoc-csv2table does not compile/work with/for pandoc 2.11

error message

cabal install pandoc-csv2table
Resolving dependencies...
Build profile: -w ghc-8.10.1 -O1
In order, the following will be built (use -v for more details):
 - csv-0.1.2 (lib:csv) (requires download & build)
 - pandoc-csv2table-1.0.8 (lib) (requires download & build)
 - pandoc-csv2table-1.0.8 (exe:pandoc-csv2table) (requires download & build)
Downloading  csv-0.1.2
Downloaded   csv-0.1.2
Downloading  pandoc-csv2table-1.0.8
Starting     csv-0.1.2 (all, legacy fallback)
Downloaded   pandoc-csv2table-1.0.8
Building     csv-0.1.2 (all, legacy fallback)
Installing   csv-0.1.2 (all, legacy fallback)
Completed    csv-0.1.2 (all, legacy fallback)
Starting     pandoc-csv2table-1.0.8 (lib)
Building     pandoc-csv2table-1.0.8 (lib)

Failed to build pandoc-csv2table-1.0.8.
Build log ( /Users/sop/.cabal/logs/ghc-8.10.1/pndc-csv2tbl-1.0.8-f1f94f0d.log
):
Configuring library for pandoc-csv2table-1.0.8..
Preprocessing library for pandoc-csv2table-1.0.8..
Building library for pandoc-csv2table-1.0.8..
[1 of 4] Compiling Text.Table.Definition ( src/Text/Table/Definition.hs, dist/build/Text/Table/Definition.o, dist/build/Text/Table/Definition.dyn_o )
[2 of 4] Compiling Text.Table.Builder ( src/Text/Table/Builder.hs, dist/build/Text/Table/Builder.o, dist/build/Text/Table/Builder.dyn_o )
[3 of 4] Compiling Text.Table.Helper ( src/Text/Table/Helper.hs, dist/build/Text/Table/Helper.o, dist/build/Text/Table/Helper.dyn_o )

src/Text/Table/Helper.hs:87:32: error:
    • The constructor ‘J.Table’ should have 6 arguments, but has been given 5
    • In the pattern: J.Table _ as ds ts tss
      In the pattern: [(J.Table _ as ds ts tss)]
      In the pattern: J.Pandoc m [(J.Table _ as ds ts tss)]
   |
87 | addInlineLabel i (J.Pandoc m [(J.Table _ as ds ts tss)]) = J.Pandoc m [(J.Table i as ds ts tss)]
   |                                ^^^^^^^^^^^^^^^^^^^^^^
cabal: Failed to build pandoc-csv2table-1.0.8 (which is required by
exe:pandoc-csv2table from pandoc-csv2table-1.0.8). See the build log above for
details.

CSV file containing empty line isn't parsed

$ cat a.md 

```{.table caption="capt" source="b.csv"}
```

$ cat b.csv 
foo,bar
,
foo,bar

$ pandoc --filter pandoc-csv2table a.md 
<p>+-------+-------+ | foo | bar | +=======+=======+ +-------+-------+ | foo | bar | +-------+-------+</p>
<p>Table: capt</p>

bug of converting table which contains 2-character-width character

test.csv

你好,世界
Hello,World!

test.md

![](test.csv)
pandoc -o output.md --filter pandoc-csv2table test.md

output.md

+--------+--------+
| 你好   | | 世界 |
+========+========+
| Hello  | World! |
+--------+--------+

it is not right, because the right should be

+--------+--------+
| 你好   | 世界   |
+========+========+
| Hello  | World! |
+--------+--------+

Thanks!

Support .tsv files with tab-separation

In my field of research, bioinformatics, TSV (tab-separated variables) is often used instead of CSV. The only difference is that the values are tab rather than comma separated. For example, GitHub supports both .csv and .tsv files when providing formatted table views.

It would be a nice addition if this filter could interpret .tsv filename extensions. I don't know anything about haskell, but it looks like the SSV package may be helpful for implementing this.

Could not find executable pandoc-csv2table

After a successful install via cabal install pandoc-csv2table, the following happens (missing PATH?):

$ pandoc --filter pandoc-csv2table table.md -o table.pdf
Error running filter pandoc-csv2table:
Could not find executable pandoc-csv2table

windows binary

Is there any windows binary for pandoc-csv2table? I don't know any haskell!

thanks

error output on arch linux

i have installed pandoc with version 2.10.1 and compiled pandoc-csv2table with stack install.

when i tried to convert markdown file, i have got following error.

pandoc-csv2table: Error in $: Incompatible API versions: encoded with [1,21] but attempted to decode with [1,17,6,1].
CallStack (from HasCallStack):
  error, called at ./Text/Pandoc/JSON.hs:122:13 in pandoc-types-1.17.6.1-8Yg10sXqtRHaIqz1Kd7Bw:Text.Pandoc.JSON
Error running filter pandoc-csv2table:
Filter returned error status 1

cabal: Could not resolve dependencies

Hi, I tried installing using cabal install pandoc-csv2table, and the result is:

Resolving dependencies...
cabal: Could not resolve dependencies:
trying: pandoc-csv2table-1.0.4 (user goal)
next goal: base (dependency of pandoc-csv2table-1.0.4)
rejecting: base-4.9.0.0/installed-4.9... (conflict: pandoc-csv2table =>
base>=4.6 && <4.9)
rejecting: base-4.9.0.0, base-4.8.2.0, base-4.8.1.0, base-4.8.0.0,
base-4.7.0.2, base-4.7.0.1, base-4.7.0.0, base-4.6.0.1, base-4.6.0.0,
base-4.5.1.0, base-4.5.0.0, base-4.4.1.0, base-4.4.0.0, base-4.3.1.0,
base-4.3.0.0, base-4.2.0.2, base-4.2.0.1, base-4.2.0.0, base-4.1.0.0,
base-4.0.0.0, base-3.0.3.2, base-3.0.3.1 (constraint from non-upgradeable
package requires installed instance)
Dependency tree exhaustively searched.

Following suggestion in When installing some filters, cabal: Could not resolve dependencies... - Google Groups: cabal install --allow-newer=base pandoc-csv2table, it's then fine.

Can you relax the dependencies in pandoc-csv2table/pandoc-csv2table.cabal? Thanks.

New release?

This library isn't present in Stackage LTS 21.1 because it wasn't building with
text 2.0 (until #38 got merged).

Would it be possible to make a new release?

Could not find executable pandoc-csv2table

After a successful install via cabal install pandoc-csv2table, the following happens (missing PATH?):

$ pandoc --filter pandoc-csv2table table.md -o table.pdf
Error running filter pandoc-csv2table:
Could not find executable pandoc-csv2table

Cannot cabal-install pandoc-csv2table on Debian Jessie

I did the following on a freshly installed Debian 8.1 "Jessie" notebook:

sudo apt-get update 
sudo apt-get upgrade
sudo apt-get install cabal-install
cabal update
cabal install cabal-install
export PATH=$HOME/.cabal/bin:$PATH
cabal update
cabal install pandoc pandoc-citeproc
cabal install pandoc-csv2table

The last command leads to an error:

kp@lenjessie:~$ cabal install pandoc-csv2table
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: pandoc-csv2table-1.0.1 (user goal)
next goal: base (dependency of pandoc-csv2table-1.0.1)
rejecting: base-4.6.0.1/installed-8aa... (conflict: pandoc-csv2table =>
base>=4.7 && <4.9)
rejecting: base-4.8.1.0, 4.8.0.0, 4.7.0.2, 4.7.0.1, 4.7.0.0, 4.6.0.1, 4.6.0.0,
4.5.1.0, 4.5.0.0, 4.4.1.0, 4.4.0.0, 4.3.1.0, 4.3.0.0, 4.2.0.2, 4.2.0.1,
4.2.0.0, 4.1.0.0, 4.0.0.0, 3.0.3.2, 3.0.3.1 (global constraint requires
installed instance)
Dependency tree exhaustively searched.

Feature Request: cli option that convert from csv to md

Hi,

Since your filter has an intermediate representation of the table in pandoc markdown format, it seems natural to provide an option to use it as a cli. e.g. < table.csv pandoc-csv2table --type="pipe" --aligns="LCR" --caption='A **caption**' --header="yes" -t markdown -f csv > table.md, that would output a pandoc markdown from a CSV with args used the same way as the attributes in code-blocks.

This will be useful in cases like:

  1. a one-time conversion (rather than continuously depending on the external CSV),

  2. in collaboration when asking colleagues to install cabal and this filter is too cumbersome,

  3. write an Automator system service (in macOS) to aid conversion in CSV to pandoc markdown on the fly in text editors.

Install issue in Debian Jessie : Constructor `Image' should have 3 arguments, but has been given 2

Hi,
I'm trying to install pandoc-csv2table in Debian Jessie following the instructions with the following environment :
~$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.6.3
~$ uname -a
Linux alex 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u6 (2015-11-09) x86_64 GNU/Linux
and get the follwing error message, is there a workaround ?

~$ cabal update
Downloading the latest package list from hackage.haskell.org
~$ cabal install pandoc-csv2table --reinstall
Resolving dependencies...
Configuring pandoc-csv2table-1.0.2...
Building pandoc-csv2table-1.0.2...
Failed to install pandoc-csv2table-1.0.2
Build log ( /home/alex/.cabal/logs/pandoc-csv2table-1.0.2.log ):
Configuring pandoc-csv2table-1.0.2...
Building pandoc-csv2table-1.0.2...
Preprocessing library pandoc-csv2table-1.0.2...
[1 of 3] Compiling Text.Table.Definition ( src/Text/Table/Definition.hs, dist/build/Text/Table/Definition.o )
[2 of 3] Compiling Text.Table.Builder ( src/Text/Table/Builder.hs, dist/build/Text/Table/Builder.o )
[3 of 3] Compiling Text.Table.Helper ( src/Text/Table/Helper.hs, dist/build/Text/Table/Helper.o )
In-place registering pandoc-csv2table-1.0.2...
Preprocessing executable 'pandoc-csv2table' for pandoc-csv2table-1.0.2...
[1 of 1] Compiling Main ( csv2table.hs, dist/build/pandoc-csv2table/pandoc-csv2table-tmp/Main.o )

csv2table.hs:68:25:
Constructor `Image' should have 3 arguments, but has been given 2
In the pattern: Image l (f, _)
In the pattern: [(Image l (f, _))]
In the pattern: Para [(Image l (f, _))]
cabal: Error: some packages failed to install:
pandoc-csv2table-1.0.2 failed during the building phase. The exception was:
ExitFailure 1

Could relative and page width options be added?

I'm using pandoc-csv2table, which generally does a good job of guessing sensible widths. But occasionally it does something strange, and then I'd like to be able to set the widths on the columns. Some of the other csv table plugins have ways of setting widths, by a list of column widths relative to tablewidth=1 (e.g. 0.1, 0.4, 0.4, 0.1), and of setting the width of the table relative to pagewidth=1. Is this a possibility for pandoc-csv2table?

cabal: Could not resolve dependencies:

I wanted to install it on ubuntu:

cabal update
cabal install cabal
cabal update
cabal install pandoc
cabal install pandoc-csv2table

resulted in:

Resolving dependencies...
cabal: Could not resolve dependencies:
trying: pandoc-csv2table-1.0.1
rejecting: base-4.6.0.1/installed-8aa... (conflict: pandoc-csv2table =>
base>=4.7 && <4.9)
rejecting: base-4.8.0.0, 4.7.0.2, 4.7.0.1, 4.7.0.0, 4.6.0.1, 4.6.0.0, 4.5.1.0,
4.5.0.0, 4.4.1.0, 4.4.0.0, 4.3.1.0, 4.3.0.0, 4.2.0.2, 4.2.0.1, 4.2.0.0,
4.1.0.0, 4.0.0.0, 3.0.3.2, 3.0.3.1 (global constraint requires installed
instance)

What can I do about that?

thanks,

grisu

Ability to set HTTP timeout length

When loading a csv file from Google docs using the URL format https://docs.google.com/spreadsheets/d/{Document-id}/gviz/tq?tqx=out:csv&sheet=sheet1 it can take around 5 seconds for the csv to be generated and downloaded. Often in this time the HTTP request timeout. Giving the option to extend the time length would greatly help the ability to integrate with Google sheets.

Standalone file `csv2table.hs` does not work out of the box

 kp@1a196:>  cat md.md 

 ````.table caption="This is the first test of the csv2table.hs filter" source="/Users/kp/csv2table-test.csv"
 ````

 kp@1a196:>  pandoc -o md.html md.md --self-contained --filter csv2table.hs

 /Users/kp/bin/csv2table.hs:58:8:
    Could not find module ‘Text.CSV’
    Perhaps you meant
      Text.CSL (from pandoc-citeproc-0.7.0.1)
      Text.CSL (needs flag -package pandoc-citeproc-0.6)
    Use -v to see a list of the files searched for.
 pandoc: Error running filter csv2table.hs

[pipe_tables] The "alignment colons" are not generated (nor is a `pipe_table`) when outputting `-t markdown`

Consider the following Markdown:

 # Headline

 ```` {.table source="./my.csv" aligns="LRCR" type="pipe" caption="Some ***caption***"}
 ````

and the following my.csv file:

Time,"*Cash* Flow","Third column"
0,-500,loooooooooooong data field with many words
1,*100*,
***2***,`2000`,shorte
**3**,30000,(second line is empty)

These commands do not create the expected output:

pandoc my.md --filter=pandoc-csv2table -t markdown
pandoc my.md --filter=pandoc-csv2table -t markdown+pipe_tables

Output is like this, _missing to be pipe_table output as well as missing the "alignment colons" in the table Markdown_:

This command works and generates the alignment colons:

pandoc my.md --filter=pandoc-csv2table -t markdown_phpextra+table_captions

[Feature request] Allow selection and ordering of CSV lines and columns by additional attributes

  1. Allow selective processing of CSV lines into the generated tables. For example by supporting an additional attribute like csvlines=3,7,33-end,2 (should be obvious what I mean with this). And the lines should appear in the same order as cvslines=... lists them.
  2. Allow selective processing of CSV columns into the table. For example by supporting an additional attribute like csvcolumns=6,3,2,13,44-end (similarly, allow re-arranging of order of columns).

Of course, these two features should also be working when combining them.

Hoping to keep you busy for a day or two now :-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.