pandoc-csv2table 1.0.7 → 1.0.8
raw patch · 7 files changed
+54/−25 lines, 7 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Text.Table.Helper: applyToTuple :: (a -> b) -> (a, a) -> (b, b)
+ Text.Table.Helper: getString :: Text -> String
Files
- CHANGELOG.md +9/−2
- README.md +3/−1
- pandoc-csv2table.cabal +2/−2
- src/Text/Table/Builder.hs +1/−1
- src/Text/Table/Definition.hs +1/−1
- src/Text/Table/Helper.hs +21/−5
- src/Text/Table/Tablify.hs +17/−13
CHANGELOG.md view
@@ -3,9 +3,14 @@ project adheres to [Semantic Versioning](http://semver.org/) and Haskell [package versioning policy](https://wiki.haskell.org/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.@@ -50,7 +55,9 @@ - The first release. -[Unreleased]: https://github.com/baig/pandoc-csv2table-filter/compare/1.0.6...HEAD+[Unreleased]: https://github.com/baig/pandoc-csv2table-filter/compare/1.0.8...HEAD+[1.0.8]: https://github.com/baig/pandoc-csv2table-filter/compare/1.0.7...1.0.8+[1.0.7]: https://github.com/baig/pandoc-csv2table-filter/compare/1.0.6...1.0.7 [1.0.6]: https://github.com/baig/pandoc-csv2table-filter/compare/1.0.5...1.0.6 [1.0.5]: https://github.com/baig/pandoc-csv2table-filter/compare/1.0.4...1.0.5 [1.0.4]: https://github.com/baig/pandoc-csv2table-filter/compare/1.0.3...1.0.4
README.md view
@@ -1,5 +1,7 @@ # Pandoc csv2table Filter +[](https://travis-ci.org/vmandela/pandoc-csv2table)+ A Pandoc filter that replaces CSV content (either inside fenced code blocks or referenced CSV files) with [Pandoc Table Markdown][tables]. @@ -149,7 +151,7 @@ ## License -Copyright © 2015-2018 [Wasif Hasan Baig](https://twitter.com/_wbaig)+Copyright © 2015-2020 [Wasif Hasan Baig](https://twitter.com/_wbaig),[Venkateswara Rao Mandela](https://vmandela.com) Source code is released under the Terms and Conditions of [MIT License](http://opensource.org/licenses/MIT).
pandoc-csv2table.cabal view
@@ -1,5 +1,5 @@ Name: pandoc-csv2table-Version: 1.0.7+Version: 1.0.8 Synopsis: Convert CSV to Pandoc Table Markdown Description: A Pandoc filter that replaces image inline or fenced code blocks with pandoc table markdown. CSV contents will be@@ -10,7 +10,7 @@ License-File: LICENSE Author: Wasif Hasan Baig <pr.wasif@gmail.com> Maintainer: Venkateswara Rao Mandela <venkat.mandela@gmail.com>-Copyright: (c) 2015-2019 Wasif Hasan Baig, Venkateswara Rao Mandela+Copyright: (c) 2015-2020 Wasif Hasan Baig, Venkateswara Rao Mandela Stability: alpha Category: Text Build-Type: Simple
src/Text/Table/Builder.hs view
@@ -27,7 +27,7 @@ Copyright : Copyright (C) 2015 Wasif Hasan Baig License : MIT - Maintainer : Wasif Hasan Baig <pr.wasif@gmail.com>+ Maintainer : Venkateswara Rao Mandela <venkat.mandela@gmail.com> Stability : alpha Functions for building Tables and converting them to markdown.
src/Text/Table/Definition.hs view
@@ -27,7 +27,7 @@ Copyright : Copyright (C) 2015 Wasif Hasan Baig License : MIT - Maintainer : Wasif Hasan Baig <pr.wasif@gmail.com>+ Maintainer : Venkateswara Rao Mandela <venkat.mandela@gmail.com> Stability : alpha Definition of 'Table' data structure for internal representation.
src/Text/Table/Helper.hs view
@@ -27,7 +27,7 @@ Copyright : Copyright (C) 2015 Wasif Hasan Baig License : MIT - Maintainer : Wasif Hasan Baig <pr.wasif@gmail.com>+ Maintainer : Venkateswara Rao Mandela <venkat.mandela@gmail.com> Stability : alpha This helper module exports functions extract values from Pandoc AST and @@ -47,12 +47,19 @@ , toAlign , tableFromImageInline , tableFromCodeBlock+ , getString+ , applyToTuple ) where import Text.CSV (CSV) import Data.List (isInfixOf) import Text.Pandoc (readMarkdown, def, ReaderOptions, readerExtensions)+#if MIN_VERSION_pandoc(2, 0, 0)+-- Extensions was split from Options in 2.0.0 import Text.Pandoc.Extensions+#else+import Text.Pandoc (pandocExtensions)+#endif import qualified Text.Pandoc.JSON as J -- Local imports import Text.Table.Definition@@ -60,9 +67,18 @@ -- imports for compatibility with Pandoc 2.0+ #if MIN_VERSION_pandoc(2,0,0) import Text.Pandoc (runPure)-import Data.Text (pack)+import Data.Text (pack, unpack) #endif +#if MIN_VERSION_pandoc(2,9,0)+getString = unpack+#else+getString = id+#endif++applyToTuple :: (a -> b) -> (a, a) -> (b, b)+applyToTuple f (x, y) = ((f x), (f y))+ -- Helper functions to manipulate the Pandoc Document and parse the -- Configuration String. @@ -91,13 +107,13 @@ _ -> Grid getTableType :: [J.Inline] -> TableType-getTableType ((J.Str s):[]) = toTableType1 s+getTableType ((J.Str s):[]) = toTableType1 (getString s) getTableType (_:is) = getTableType is getTableType [] = Grid -- | Whether to treat first line of CSV as a header or not. isHeaderPresent :: [J.Inline] -> Bool-isHeaderPresent ((J.Str s):[]) = not $ "n" `isInfixOf` s+isHeaderPresent ((J.Str s):[]) = not $ "n" `isInfixOf` (getString s) isHeaderPresent (_:is) = isHeaderPresent is isHeaderPresent [] = True @@ -120,7 +136,7 @@ -- | Parse Config String for alignment information getAligns :: [J.Inline] -> [Align]-getAligns ((J.Str s):[]) = toAlign s+getAligns ((J.Str s):[]) = toAlign (getString s) getAligns (_:is) = getAligns is getAligns [] = []
src/Text/Table/Tablify.hs view
@@ -27,7 +27,7 @@ Copyright : Copyright (C) 2015 Wasif Hasan Baig License : MIT - Maintainer : Wasif Hasan Baig <pr.wasif@gmail.com>+ Maintainer : Venkateswara Rao Mandela <venkat.mandela@gmail.com> Stability : alpha Function for operating on Pandoc fenced code blocks or image blocks@@ -49,12 +49,12 @@ -- variant 1: Referencing CSV file in Image Links #if MIN_VERSION_pandoc(1,16,0) -- Image Attr [Inline] Target -- ^ Image: alt text (list of inlines), target-tablifyCsvLinks (Para [(Image _ l (f, _))]) | "csv" `isSuffixOf` f = do+tablifyCsvLinks (Para [(Image _ l (f, _))]) | "csv" `isSuffixOf` (getString f) = do #else -- Image [Inline] Target -- ^ Image: alt text (list of inlines), target tablifyCsvLinks (Para [(Image l (f, _))]) | "csv" `isSuffixOf` f = do #endif- csv <- parseCSVFromFile f+ csv <- parseCSVFromFile $ getString f case csv of (Left _) -> return [] (Right xss) -> return .@@ -62,17 +62,17 @@ tableFromImageInline l $ xss -- variant 2 and 3: Fenced Code Blocks-tablifyCsvLinks b@(CodeBlock (_, cs, as) s) | "table" `elem` cs = do- let file = getAtr "source" as+tablifyCsvLinks b@(CodeBlock (_, cs, as) s) | "table" `elem` (map getString cs) = do+ let file = getAtr "source" as1 case file of -- variant 2: Referencing CSV file in Fenced Code Blocks- "" -> case s of+ "" -> case s1 of "" -> return [b]- _ -> case (parseCSV "" s) of+ _ -> case (parseCSV "" s1) of (Left _) -> return [] (Right xss) -> return . toBlocks .- tableFromCodeBlock as $+ tableFromCodeBlock as1 $ xss -- variant 3:Including CSV content inside Fenced Code Blocks _ -> do@@ -81,18 +81,22 @@ (Left _) -> return [] (Right xss) -> return . toBlocks .- tableFromCodeBlock as $+ tableFromCodeBlock as1 $ xss+ where s1 = getString s+ as1 = (map (applyToTuple getString) as ) -- Return input unchanged in case of no match tablifyCsvLinks x = return [x] tablifyCsvLinksPure :: Block -> [Block]-tablifyCsvLinksPure b@(CodeBlock (_, cs, as) s) | "table" `elem` cs = do- case s of+tablifyCsvLinksPure b@(CodeBlock (_, cs, as) s) | "table" `elem` (map getString cs) = do+ case s1 of "" -> return b- _ -> case (parseCSV "" s) of+ _ -> case (parseCSV "" s1) of (Left _) -> return b (Right xss) -> toBlocks .- tableFromCodeBlock as $+ tableFromCodeBlock as1 $ xss+ where s1 = getString s+ as1 = (map (applyToTuple getString) as ) tablifyCsvLinksPure x = return x