packages feed

pandoc-linear-table (empty) → 0.2.0.5

raw patch · 5 files changed

+204/−0 lines, 5 filesdep +basedep +pandocdep +pandoc-linear-table

Dependencies added: base, pandoc, pandoc-linear-table, pandoc-types, text

Files

+ CHANGELOG.md view
@@ -0,0 +1,11 @@+# Revision history for pandoc-linear-table++0.2.0.5 Packaged as a Nix flake.++0.2.0.4 Improved error message.++0.2.0.3 Reformatted source code.++0.2.0.0 Factored out transform into a separate library for use with Hakyll.++0.1.0.0 Initial release
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2022-2023, Amy de Buitléir++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Amy de Buitléir nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ app/Main.hs view
@@ -0,0 +1,17 @@+{-|+Module      : Main+Description : An easy way to create tables with wrapped text in Markdown.+Copyright   : (c) 2020-2023 Amy de Buitléir+License     : BSD--3+Maintainer  : amy@nualeargais.ie+Stability   : experimental+Portability : POSIX++See <https://github.com/mhwombat/pandoc-linear-table> for information+on how to use this filter.+-}+import Text.Pandoc.Filters.LinearTable (formatLinearTable)+import Text.Pandoc.JSON                (toJSONFilter)++main :: IO ()+main = toJSONFilter formatLinearTable
+ pandoc-linear-table.cabal view
@@ -0,0 +1,47 @@+cabal-version:   3.0+name:            pandoc-linear-table+version:         0.2.0.5+synopsis:+    A pandoc filter that provides a Markdown extension to wrap text in table cells.+description:+  For more information and a tutorial on how to use this package,+  please see the README at <https://github.com/mhwombat/pandoc-linear-table#readme>.+homepage:        https://github.com/mhwombat/pandoc-linear-table+bug-reports:     https://github.com/mhwombat/pandoc-linear-table/issues+license:         BSD-3-Clause+license-file:    LICENSE+author:          Amy de Buitléir+maintainer:      amy@nualeargais.ie+copyright:       (c) 2020-2023 Amy de Buitléir+category:        Text+build-type:      Simple+extra-doc-files: CHANGELOG.md++source-repository head+  type:              git+  location:          https://github.com/mhwombat/pandoc-linear-table.git++common common-stuff+  default-language: Haskell2010+  default-extensions: ImportQualifiedPost+  build-depends:+    base >= 4.16.4 && < 4.17,+    pandoc-types >= 1.22.2 && < 1.23+  ghc-options: -Wall  -Wunused-packages++library+  import:           common-stuff+  hs-source-dirs:   src+  exposed-modules:+    Text.Pandoc.Filters.LinearTable+  build-depends:+    pandoc >= 2.19.2 && < 2.20,+    text >= 1.2.5 && < 1.3++executable pandoc-linear-table+  import:           common-stuff+  hs-source-dirs:   app+  main-is:          Main.hs+  build-depends:+      pandoc-linear-table+
+ src/Text/Pandoc/Filters/LinearTable.hs view
@@ -0,0 +1,99 @@+{-|+Module      : LinearTable+Description : An easy way to create tables with wrapped text in Markdown.+Copyright   : (c) 2020-2023 Amy de Buitléir+License     : BSD--3+Maintainer  : amy@nualeargais.ie+Stability   : experimental+Portability : POSIX++See <https://github.com/mhwombat/pandoc-linear-table> for information+on how to use this filter.+-}++{-# LANGUAGE OverloadedStrings #-}++module Text.Pandoc.Filters.LinearTable+  (+    transform,+    formatLinearTable+  ) where++import Data.Foldable    (foldl')+import Data.Text        qualified as T+import Text.Pandoc      qualified as P+import Text.Pandoc.Walk (walk)+++-- | A transformation that can be used with Hakyll.+transform :: P.Pandoc -> P.Pandoc+transform = walk formatLinearTable++-- | Exported for use by the executable.+formatLinearTable :: P.Block -> P.Block+formatLinearTable x@(P.CodeBlock (_,cs,_) s)+  | null cs                  = x+  | head cs == "linear-table" = toTable . splitRows $ T.lines s+  | otherwise                = x+formatLinearTable x = x++toTable :: [[T.Text]] -> P.Block+toTable xss = P.Table attr defaultTableCaption colSpecs+                    defaultTableHeader [toTableBody xss]+                    defaultTableFooter+  where attr = ("",["linear-table"],[])+        colSpecs = replicate nCols defaultColSpec+        nCols = maximum $ map length xss+++toTableBody :: [[T.Text]] -> P.TableBody+toTableBody = P.TableBody P.nullAttr (P.RowHeadColumns 0) []+                  . map toTableRow+++toTableRow :: [T.Text] -> P.Row+toTableRow = P.Row P.nullAttr . map toCell++toCell :: T.Text -> P.Cell+toCell = blocksToCell . map removePara . parseBlocks++blocksToCell :: [P.Block] -> P.Cell+blocksToCell+  = P.Cell P.nullAttr P.AlignDefault (P.RowSpan 1) (P.ColSpan 1)++removePara :: P.Block -> P.Block+removePara (P.Para xs) = P.Plain xs+removePara x           = x++splitRows :: Foldable t => t T.Text -> [[T.Text]]+splitRows xs = reverse . map reverse $ foldl' splitter [] xs++splitter :: [[T.Text]] -> T.Text -> [[T.Text]]+splitter [] x | x == ""    = []+              | otherwise = [[x]]+splitter accum x | x == ""    = []:accum+                 | otherwise = (x:(head accum)) : tail accum+++++readDefaults :: P.ReaderOptions+readDefaults = P.def { P.readerStandalone = True,+                       P.readerExtensions = P.pandocExtensions }++parseBlocks :: T.Text -> [P.Block]+parseBlocks s = f . P.runPure $ P.readMarkdown readDefaults s+  where f (Right (P.Pandoc _ bs)) = bs+        f (Left e) = error $ "readMarkdown failed: " ++ show e++defaultColSpec :: P.ColSpec+defaultColSpec = (P.AlignDefault, P.ColWidthDefault)++defaultTableCaption :: P.Caption+defaultTableCaption = P.Caption Nothing []++defaultTableHeader :: P.TableHead+defaultTableHeader = P.TableHead P.nullAttr []++defaultTableFooter :: P.TableFoot+defaultTableFooter = P.TableFoot P.nullAttr []