pandoc-csv2table 1.0.0 → 1.0.1
raw patch · 4 files changed
+195/−88 lines, 4 filesdep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base
API changes (from Hackage documentation)
- Text.Table.Definition: instance Eq TableType
- Text.Table.Definition: instance Show Align
- Text.Table.Definition: instance Show CaptionPos
- Text.Table.Definition: instance Show Cell
- Text.Table.Definition: instance Show Column
- Text.Table.Definition: instance Show Header
- Text.Table.Definition: instance Show Row
- Text.Table.Definition: instance Show Table
- Text.Table.Definition: instance Show TableType
+ Text.Table.Definition: instance GHC.Classes.Eq Text.Table.Definition.TableType
+ Text.Table.Definition: instance GHC.Show.Show Text.Table.Definition.Align
+ Text.Table.Definition: instance GHC.Show.Show Text.Table.Definition.CaptionPos
+ Text.Table.Definition: instance GHC.Show.Show Text.Table.Definition.Cell
+ Text.Table.Definition: instance GHC.Show.Show Text.Table.Definition.Column
+ Text.Table.Definition: instance GHC.Show.Show Text.Table.Definition.Header
+ Text.Table.Definition: instance GHC.Show.Show Text.Table.Definition.Row
+ Text.Table.Definition: instance GHC.Show.Show Text.Table.Definition.Table
+ Text.Table.Definition: instance GHC.Show.Show Text.Table.Definition.TableType
Files
- CHANGELOG.md +20/−0
- README.md +89/−17
- pandoc-csv2table.cabal +72/−68
- src/Text/Table/Helper.hs +14/−3
+ CHANGELOG.md view
@@ -0,0 +1,20 @@+# Change Log+All notable changes to this project will be documented in this file. This+project adheres to [Semantic Versioning](http://semver.org/) and Haskell+[package versioning policy](https://wiki.haskell.org/Package_versioning_policy).++## [Unreleased][unreleased]++## Changed+- Updated cabal file++## [1.0.1] - 2015-06-02++### Fixed+- Now handling `readMarkdown` conditionally using CPP macro (fixes issue #8).++## 1.0.0+- The first release.++[unreleased]: https://github.com/baig/pandoc-csv2table-filter/compare/1.0.1...HEAD+[1.0.1]: https://github.com/baig/pandoc-csv2table-filter/compare/1.0.0...1.0.1
README.md view
@@ -1,31 +1,82 @@-# pandoc-csv2table-filter+# Pandoc csv2table Filter -A Pandoc filter that replaces image links having *.csv extension with-[Pandoc Table Markdown][1].+A Pandoc filter that replaces CSV content (either inside fenced code blocks or referenced CSV files) with+[Pandoc Table Markdown][tables]. ![A CSV file rendered to Markdown and PDF][png] +[png]: Examples/demo.png++## 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][gist]. Clone it and make it an executable script by+ running:+ + > ```+ > chmod +x pandoc-csv2table.hs+ > ```+ +[gist]: https://gist.github.com/baig/b69e3146251bd90d12e7+ ## Usage -In your markdown, include the csv file as shown below.+There are three ways to include CSV in your markdown. -> \!\[This text will become the table caption\](table.csv)+1. **Referencing CSV file in Image Links:** -You can use Pandoc Markdown in the CSV file.-It will be parsed by the Pandoc Markdown Reader before insertion into the-document.+ ```+ + ```+ +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:** -See [example.md][example-md] and the rendered [pdf][example-pdf] version in-the Examples folder for more details on usage.+ ```{.table aligns="LCR" caption="This is the **caption**" header="yes"} + Fruit, Quantity, Price + apples, 15, 3.24 + oranges, 12, 2.22 + ``` -## Configuration String+ Only code blocks having `.table` class will be processed. -A configuration string lets you specify+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. +See [example.md][md] and the rendered [pdf][] version in the Examples folder+for more details on usage.++[md]: Examples/example.md+[pdf]: Examples/example.pdf++## Options++You can specify a [configuration string][cfg] for image links and+[attributes][atr] 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 +[cfg]: README.md#configuration-string+[atr]: README.md#attributes++### Configuration String+ It is included right before the closing square bracket **without any space in between**, as shown in the example below. @@ -55,6 +106,30 @@ 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 [Wasif Hasan Baig](https://twitter.com/_wbaig)@@ -63,8 +138,5 @@ Please refer to the [License file][license] in the project's root directory. -[png]: https://raw.githubusercontent.com/baig/pandoc-csv2table-filter/master/Examples/demo.png-[license]: https://raw.githubusercontent.com/baig/pandoc-csv2table-filter/master/LICENSE-[example-md]: https://raw.githubusercontent.com/baig/pandoc-csv2table-filter/master/Examples/example.md-[example-pdf]: https://github.com/baig/pandoc-csv2table-filter/blob/master/Examples/example.pdf-[1]: http://pandoc.org/README.html#tables+[license]: LICENSE+[tables]: http://pandoc.org/README.html#tables
pandoc-csv2table.cabal view
@@ -1,76 +1,80 @@-Name: pandoc-csv2table-Version: 1.0.0-Synopsis: Convert CSV to Pandoc Table Markdown-Description: A Pandoc filter that replaces image inline or fenced code- blocks with pandoc markdown tables.- .- Image links must have a "csv" extension.- Include the csv file in markdown as- .- > - .- You can also use fenced code blocks to reference an- external CSV file using the "source" attribute.- .- > ```{.table caption="This is the **caption**" source="table.csv"}- > ```- .- You can include the CSV contents inside fenced code blocks- and omit the source attribute.- .- > ```{.table caption="This is the **caption**"}- > Fruit, Quantity, Price- > apples, 15, 3.24- > oranges, 12, 2.22- > ```- .- CSV contents will be parsed by the pandoc markdown reader.- .- You can see a rendered PDF file with tables generated from- CSV files at <https://github.com/baig/pandoc-csv2table-filter/blob/master/Examples/example.pdf Example>.- .- For more information, see <https://github.com/baig/pandoc-csv2table-filter/blob/master/README.md README>- at project's source repository.+Name: pandoc-csv2table+Version: 1.0.1+Synopsis: Convert CSV to Pandoc Table Markdown+Description: A Pandoc filter that replaces image inline or fenced code+ blocks with pandoc markdown tables.+ .+ Image links must have a "csv" extension.+ Include the csv file in markdown as+ .+ @+ + @+ .+ You can also use fenced code blocks to reference an+ external CSV file using the "source" attribute.+ .+ > ```{.table caption="This is the **caption**" source="table.csv"}+ > ```+ .+ You can include the CSV contents inside fenced code blocks+ and omit the source attribute.+ .+ > ```{.table caption="This is the **caption**"}+ > Fruit, Quantity, Price+ > apples, 15, 3.24+ > oranges, 12, 2.22+ > ```+ .+ CSV contents will be parsed by the pandoc markdown reader.+ .+ You can see a rendered PDF file with tables generated from+ CSV files at <https://github.com/baig/pandoc-csv2table-filter/blob/master/Examples/example.pdf Example>.+ .+ For more information, see <https://github.com/baig/pandoc-csv2table-filter/blob/master/README.md README>+ at project's source repository. -Homepage: https://github.com/baig/pandoc-csv2table-filter-Bug-Reports: https://github.com/baig/pandoc-csv2table-filter/issues-License: MIT-License-File: LICENSE-Author: Wasif Hasan Baig <pr.wasif@gmail.com>-Maintainer: Wasif Hasan Baig <pr.wasif@gmail.com>-Copyright: (c) 2015 Wasif Hasan Baig-Stability: alpha-Category: Text-Build-Type: Simple-Extra-Source-Files: README.md-Cabal-Version: >=1.10-Source-repository head- type: git- location: git://github.com/baig/pandoc-csv2table-filter.git+Homepage: https://github.com/baig/pandoc-csv2table-filter+Bug-Reports: https://github.com/baig/pandoc-csv2table-filter/issues+License: MIT+License-File: LICENSE+Author: Wasif Hasan Baig <pr.wasif@gmail.com>+Maintainer: Wasif Hasan Baig <pr.wasif@gmail.com>+Copyright: (c) 2015 Wasif Hasan Baig+Stability: alpha+Category: Text+Build-Type: Simple+Data-Files: README.md+Extra-Source-Files: CHANGELOG.md+Cabal-Version: >=1.10+Source-repository head+ type: git+ location: git://github.com/baig/pandoc-csv2table-filter.git Library- Build-Depends: base >=4.8 && <4.9,- csv >= 0.1.2,- text >= 0.11 && < 1.3,- pandoc >= 1.13.0.0,- pandoc-types >= 1.12.0.0- Hs-Source-Dirs: src- Exposed-Modules: Text.Table.Definition,- Text.Table.Builder,- Text.Table.Helper- Buildable: True- Default-Language: Haskell2010+ Build-Depends: base >=4.8 && <4.9,+ csv >= 0.1.2,+ text >= 0.11 && < 1.3,+ pandoc >= 1.13.0.0,+ pandoc-types >= 1.12.0.0+ Hs-Source-Dirs: src+ Default-Extensions: CPP+ Exposed-Modules: Text.Table.Definition,+ Text.Table.Builder,+ Text.Table.Helper+ Buildable: True+ Default-Language: Haskell2010 Executable pandoc-csv2table- Build-Depends: base >=4.8 && <4.9,- csv >= 0.1.2,- pandoc >= 1.13.0.0,- pandoc-types >= 1.12.0.0,- pandoc-csv2table >= 1.0.0- Hs-Source-Dirs: .- Main-Is: csv2table.hs- Buildable: True- Default-Language: Haskell2010+ Build-Depends: base >=4.8 && <4.9,+ csv >= 0.1.2,+ pandoc >= 1.13.0.0,+ pandoc-types >= 1.12.0.0,+ pandoc-csv2table >= 1.0.0+ Hs-Source-Dirs: .+ Main-Is: csv2table.hs+ Buildable: True+ Default-Language: Haskell2010
src/Text/Table/Helper.hs view
@@ -51,7 +51,7 @@ import Text.CSV (CSV) import Data.List (isInfixOf)-import Text.Pandoc (readMarkdown, def)+import Text.Pandoc (readMarkdown, def, ReaderOptions) import qualified Text.Pandoc.JSON as J -- Local imports import Text.Table.Definition@@ -133,14 +133,25 @@ -- | Make Pandoc Table from Image Inline tableFromImageInline :: [J.Inline] -> CSV -> J.Pandoc tableFromImageInline l = addInlineLabel (removeConfigString l) .- readMarkdown def .+ readMarkdown' def . toMarkdown (getTableType l) AfterTable . mkTable "" (getAligns l) (isHeaderPresent l) -- | Make Pandoc Table from Code Block tableFromCodeBlock :: Atrs -> CSV -> J.Pandoc-tableFromCodeBlock as = readMarkdown def .+tableFromCodeBlock as = readMarkdown' def . toMarkdown (toTableType $ getAtr "type" as) AfterTable . mkTable (getAtr "caption" as) (toAlign $ getAtr "aligns" as) (isHeaderPresent1 $ getAtr "header" as)++#if MIN_VERSION_pandoc(1,14,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+#else+readMarkdown' :: ReaderOptions -> String -> J.Pandoc+readMarkdown' = readMarkdown+#endif