git.iko.soy/typeable/pandoc
on master help sign in
Moved gridTable from Markdown writer to Writers.Shared.
e7336b1John MacFarlane
src/Text/Pandoc/Writers/Haddock.hs+1−1
@@ -45,7 +45,7 @@ import Text.Pandoc.Pretty
45import Text.Pandoc.Shared
45import Text.Pandoc.Shared
46import Text.Pandoc.Templates (renderTemplate')
46import Text.Pandoc.Templates (renderTemplate')
47import Text.Pandoc.Writers.Math (texMathToInlines)
47import Text.Pandoc.Writers.Math (texMathToInlines)
48−import Text.Pandoc.Writers.Shared
48+import Text.Pandoc.Writers.Shared hiding (gridTable)
49
49
50type Notes = [[Block]]
50type Notes = [[Block]]
51data WriterState = WriterState { stNotes :: Notes }
51data WriterState = WriterState { stNotes :: Notes }
src/Text/Pandoc/Writers/Markdown.hs−41
@@ -705,47 +705,6 @@ pandocTable opts headless aligns widths rawHeaders rawRows = do
705 else border
705 else border
706 return $ head'' $$ underline $$ body $$ bottom
706 return $ head'' $$ underline $$ body $$ bottom
707
707
708−gridTable :: PandocMonad m => Bool -> [Alignment] -> [Int]
709− -> [Doc] -> [[Doc]] -> MD m Doc
710−gridTable headless aligns widthsInChars headers' rawRows = do
711− let hpipeBlocks blocks = hcat [beg, middle, end]
712− where h = maximum (1 : map height blocks)
713− sep' = lblock 3 $ vcat (map text $ replicate h " | ")
714− beg = lblock 2 $ vcat (map text $ replicate h "| ")
715− end = lblock 2 $ vcat (map text $ replicate h " |")
716− middle = chomp $ hcat $ intersperse sep' blocks
717− let makeRow = hpipeBlocks . zipWith lblock widthsInChars
718− let head' = makeRow headers'
719− let rows' = map (makeRow . map chomp) rawRows
720− let borderpart ch align widthInChars =
721− let widthInChars' = if widthInChars < 1 then 1 else widthInChars
722− in (if (align == AlignLeft || align == AlignCenter)
723− then char ':'
724− else char ch) <>
725− text (replicate widthInChars' ch) <>
726− (if (align == AlignRight || align == AlignCenter)
727− then char ':'
728− else char ch)
729− let border ch aligns' widthsInChars' =
730− char '+' <>
731− hcat (intersperse (char '+') (zipWith (borderpart ch)
732− aligns' widthsInChars')) <> char '+'
733− let body = vcat $ intersperse (border '-' (repeat AlignDefault) widthsInChars)
734− rows'
735− let head'' = if headless
736− then empty
737− else head' $$ border '=' aligns widthsInChars
738− if headless
739− then return $
740− border '-' aligns widthsInChars $$
741− body $$
742− border '-' (repeat AlignDefault) widthsInChars
743− else return $
744− border '-' (repeat AlignDefault) widthsInChars $$
745− head'' $$
746− body $$
747− border '-' (repeat AlignDefault) widthsInChars
748−
749itemEndsWithTightList :: [Block] -> Bool
708itemEndsWithTightList :: [Block] -> Bool
750itemEndsWithTightList bs =
709itemEndsWithTightList bs =
751 case bs of
710 case bs of
src/Text/Pandoc/Writers/Shared.hs+42−1
@@ -39,13 +39,14 @@ module Text.Pandoc.Writers.Shared (
39 , tagWithAttrs
39 , tagWithAttrs
40 , fixDisplayMath
40 , fixDisplayMath
41 , unsmartify
41 , unsmartify
42+ , gridTable
42 )
43 )
43where
44where
44import Control.Monad (liftM)
45import Control.Monad (liftM)
45import Data.Aeson (FromJSON (..), Result (..), ToJSON (..), Value (Object),
46import Data.Aeson (FromJSON (..), Result (..), ToJSON (..), Value (Object),
46 encode, fromJSON)
47 encode, fromJSON)
47import qualified Data.HashMap.Strict as H
48import qualified Data.HashMap.Strict as H
48−import Data.List (groupBy)
49+import Data.List (groupBy, intersperse)
49import qualified Data.Map as M
50import qualified Data.Map as M
50import Data.Maybe (isJust)
51import Data.Maybe (isJust)
51import qualified Data.Text as T
52import qualified Data.Text as T
@@ -216,3 +217,43 @@ unsmartify opts ('\8212':xs)
216unsmartify opts (x:xs) = x : unsmartify opts xs
217unsmartify opts (x:xs) = x : unsmartify opts xs
217unsmartify _ [] = []
218unsmartify _ [] = []
218
219
220+gridTable :: Monad m => Bool -> [Alignment] -> [Int]
221+ -> [Doc] -> [[Doc]] -> m Doc
222+gridTable headless aligns widthsInChars headers' rawRows = do
223+ let hpipeBlocks blocks = hcat [beg, middle, end]
224+ where h = maximum (1 : map height blocks)
225+ sep' = lblock 3 $ vcat (map text $ replicate h " | ")
226+ beg = lblock 2 $ vcat (map text $ replicate h "| ")
227+ end = lblock 2 $ vcat (map text $ replicate h " |")
228+ middle = chomp $ hcat $ intersperse sep' blocks
229+ let makeRow = hpipeBlocks . zipWith lblock widthsInChars
230+ let head' = makeRow headers'
231+ let rows' = map (makeRow . map chomp) rawRows
232+ let borderpart ch align widthInChars =
233+ let widthInChars' = if widthInChars < 1 then 1 else widthInChars
234+ in (if (align == AlignLeft || align == AlignCenter)
235+ then char ':'
236+ else char ch) <>
237+ text (replicate widthInChars' ch) <>
238+ (if (align == AlignRight || align == AlignCenter)
239+ then char ':'
240+ else char ch)
241+ let border ch aligns' widthsInChars' =
242+ char '+' <>
243+ hcat (intersperse (char '+') (zipWith (borderpart ch)
244+ aligns' widthsInChars')) <> char '+'
245+ let body = vcat $ intersperse (border '-' (repeat AlignDefault) widthsInChars)
246+ rows'
247+ let head'' = if headless
248+ then empty
249+ else head' $$ border '=' aligns widthsInChars
250+ if headless
251+ then return $
252+ border '-' aligns widthsInChars $$
253+ body $$
254+ border '-' (repeat AlignDefault) widthsInChars
255+ else return $
256+ border '-' (repeat AlignDefault) widthsInChars $$
257+ head'' $$
258+ body $$
259+ border '-' (repeat AlignDefault) widthsInChars