From be12ae3bca4f1c2d712e412b11a14b6473c7ab10 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 16 Mar 2018 22:38:34 -0700 Subject: Better table handling for Haddock. In the reader, we use the new Table type in Haddock. Note that tables with col/rowspans will not translate well into Pandoc. In the writer, we now render tables always as grid tables, since Haddock supports these. --- src/Text/Pandoc/Readers/Haddock.hs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/Text/Pandoc/Readers') diff --git a/src/Text/Pandoc/Readers/Haddock.hs b/src/Text/Pandoc/Readers/Haddock.hs index 2f76fc1a0..b593c4cc8 100644 --- a/src/Text/Pandoc/Readers/Haddock.hs +++ b/src/Text/Pandoc/Readers/Haddock.hs @@ -19,7 +19,7 @@ import Data.List (intersperse, stripPrefix) import Data.Maybe (fromMaybe) import Data.Text (Text, unpack) import Documentation.Haddock.Parser -import Documentation.Haddock.Types +import Documentation.Haddock.Types as H import Text.Pandoc.Builder (Blocks, Inlines) import qualified Text.Pandoc.Builder as B import Text.Pandoc.Class (PandocMonad) @@ -85,6 +85,18 @@ docHToBlocks d' = DocProperty s -> B.codeBlockWith ("",["property","haskell"],[]) (trim s) DocExamples es -> mconcat $ map (\e -> makeExample ">>>" (exampleExpression e) (exampleResult e)) es + DocTable H.Table{ tableHeaderRows = headerRows + , tableBodyRows = bodyRows + } + -> let toCells = map (docHToBlocks . tableCellContents) . tableRowCells + (header, body) = + if null headerRows + then ([], map toCells bodyRows) + else (toCells (head headerRows), + map toCells (tail headerRows ++ bodyRows)) + colspecs = replicate (maximum (map length body)) + (AlignDefault, 0.0) + in B.table mempty colspecs header body where inlineFallback = B.plain $ docHToInlines False d' consolidatePlains = B.fromList . consolidatePlains' . B.toList @@ -133,6 +145,7 @@ docHToInlines isCode d' = DocAName s -> B.spanWith (s,["anchor"],[]) mempty DocProperty _ -> mempty DocExamples _ -> mempty + DocTable _ -> mempty -- | Create an 'Example', stripping superfluous characters as appropriate makeExample :: String -> String -> [String] -> Blocks -- cgit v1.2.3