pandoc-csv2table 1.0.3 → 1.0.4
raw patch · 5 files changed
+100/−40 lines, 5 files
Files
- CHANGELOG.md +13/−2
- README.md +3/−0
- csv2table.hs +1/−37
- pandoc-csv2table.cabal +2/−1
- src/Text/Table/Tablify.hs +81/−0
CHANGELOG.md view
@@ -4,9 +4,18 @@ [package versioning policy](https://wiki.haskell.org/Package_versioning_policy). -## [Unreleased][unreleased]+## [Unreleased] +## [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@@ -25,6 +34,8 @@ ## 1.0.0 - The first release. -[unreleased]: https://github.com/baig/pandoc-csv2table-filter/compare/1.0.3...HEAD++[Unreleased]: https://github.com/baig/pandoc-csv2table-filter/compare/1.0.4...HEAD+[1.0.4]: https://github.com/baig/pandoc-csv2table-filter/compare/1.0.3...1.0.4 [1.0.2]: https://github.com/baig/pandoc-csv2table-filter/compare/1.0.1...1.0.3 [1.0.1]: https://github.com/baig/pandoc-csv2table-filter/compare/1.0.0...1.0.1
README.md view
@@ -27,6 +27,9 @@ [gist]: https://gist.github.com/baig/b69e3146251bd90d12e7 +You can also use this filter in your Pandoc application by calling+`tablifyCsvlinks`.+ ## Usage ### Referencing or including CSV
csv2table.hs view
@@ -59,43 +59,7 @@ import Data.List (isSuffixOf) import Text.Pandoc.JSON (Block(Para, CodeBlock), Inline(Image), toJSONFilter) -- Local imports-import Text.Table.Helper+import Text.Table.Tablify main :: IO () main = toJSONFilter tablifyCsvLinks--tablifyCsvLinks :: Block -> IO [Block]-#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-#else--- Image [Inline] Target -- ^ Image: alt text (list of inlines), target-tablifyCsvLinks (Para [(Image l (f, _))]) | "csv" `isSuffixOf` f = do-#endif- csv <- parseCSVFromFile f- case csv of- (Left _) -> return []- (Right xss) -> return .- toBlocks .- tableFromImageInline l $- xss-tablifyCsvLinks b@(CodeBlock (_, cs, as) s) | "table" `elem` cs = do- let file = getAtr "source" as- case file of- "" -> case s of- "" -> return [b]- _ -> case (parseCSV "" s) of- (Left _) -> return []- (Right xss) -> return .- toBlocks .- tableFromCodeBlock as $- xss- _ -> do- csv <- parseCSVFromFile file- case csv of- (Left _) -> return []- (Right xss) -> return .- toBlocks .- tableFromCodeBlock as $- xss-tablifyCsvLinks x = return [x]
pandoc-csv2table.cabal view
@@ -1,5 +1,5 @@ Name: pandoc-csv2table-Version: 1.0.3+Version: 1.0.4 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@@ -32,6 +32,7 @@ Exposed-Modules: Text.Table.Definition, Text.Table.Builder, Text.Table.Helper+ Text.Table.Tablify Buildable: True Default-Language: Haskell2010
+ src/Text/Table/Tablify.hs view
@@ -0,0 +1,81 @@+{-+The MIT License (MIT)++Copyright (c) 2015 Wasif Hasan Baig <pr.wasif@gmail.com>++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.+-}++{- |+ Module : Text.Table.Tablify+ Copyright : Copyright (C) 2015 Wasif Hasan Baig+ License : MIT++ Maintainer : Wasif Hasan Baig <pr.wasif@gmail.com>+ Stability : alpha++Function for operating on Pandoc fenced code blocks or image blocks+with the ".table" attribute and converting them into Pandoc tables.+-}++module Text.Table.Tablify (+ tablifyCsvLinks+ ) where++import Text.CSV (parseCSV, parseCSVFromFile)+import Text.Pandoc.JSON (Block(Para, CodeBlock), Inline(Image), toJSONFilter)+import Data.List (isSuffixOf)+-- Local imports+import Text.Table.Helper++tablifyCsvLinks :: Block -> IO [Block]+#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+#else+-- Image [Inline] Target -- ^ Image: alt text (list of inlines), target+tablifyCsvLinks (Para [(Image l (f, _))]) | "csv" `isSuffixOf` f = do+#endif+ csv <- parseCSVFromFile f+ case csv of+ (Left _) -> return []+ (Right xss) -> return .+ toBlocks .+ tableFromImageInline l $+ xss+tablifyCsvLinks b@(CodeBlock (_, cs, as) s) | "table" `elem` cs = do+ let file = getAtr "source" as+ case file of+ "" -> case s of+ "" -> return [b]+ _ -> case (parseCSV "" s) of+ (Left _) -> return []+ (Right xss) -> return .+ toBlocks .+ tableFromCodeBlock as $+ xss+ _ -> do+ csv <- parseCSVFromFile file+ case csv of+ (Left _) -> return []+ (Right xss) -> return .+ toBlocks .+ tableFromCodeBlock as $+ xss+tablifyCsvLinks x = return [x]