diff options
author | John MacFarlane <jgm@berkeley.edu> | 2020-04-17 10:04:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-17 10:04:39 -0700 |
commit | 906305de789c83f9fdcc2c7d30044acf97e89582 (patch) | |
tree | f359e991e60e7324f11e73a40259ed9dc3e4b91b /src/Text/Pandoc/Readers | |
parent | f0f3cc14beeea51f703f7cfc8b40ebf3de2d0a05 (diff) | |
parent | d1521af8fb0d3e8ee4104224e4d5e0b6e6bfad8c (diff) | |
download | pandoc-906305de789c83f9fdcc2c7d30044acf97e89582.tar.gz |
Merge pull request #6224 from despresc/better-tables
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r-- | src/Text/Pandoc/Readers/CSV.hs | 18 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/CommonMark.hs | 24 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/DocBook.hs | 46 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Docx.hs | 35 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/DokuWiki.hs | 10 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/HTML.hs | 22 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Haddock.hs | 10 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Ipynb.hs | 2 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/JATS.hs | 59 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Jira.hs | 2 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 41 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Man.hs | 13 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 37 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/MediaWiki.hs | 14 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Muse.hs | 19 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Odt/ContentReader.hs | 4 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Org/Blocks.hs | 24 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/RST.hs | 67 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/TWiki.hs | 18 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Textile.hs | 11 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Txt2Tags.hs | 10 |
21 files changed, 303 insertions, 183 deletions
diff --git a/src/Text/Pandoc/Readers/CSV.hs b/src/Text/Pandoc/Readers/CSV.hs index fa358424f..384687a6a 100644 --- a/src/Text/Pandoc/Readers/CSV.hs +++ b/src/Text/Pandoc/Readers/CSV.hs @@ -30,13 +30,19 @@ readCSV :: PandocMonad m -> m Pandoc readCSV _opts s = case parseCSV defaultCSVOptions (crFilter s) of - Right (r:rs) -> return $ B.doc $ B.table capt (zip aligns widths) hdrs rows - where capt = mempty + Right (r:rs) -> return $ B.doc $ B.table capt + (zip aligns widths) + (TableHead nullAttr hdrs) + [TableBody nullAttr 0 [] rows] + (TableFoot nullAttr []) + where capt = B.emptyCaption numcols = length r - toplain = B.plain . B.text . T.strip - hdrs = map toplain r - rows = map (map toplain) rs + toplain = B.simpleCell . B.plain . B.text . T.strip + toRow = Row nullAttr . map toplain + toHeaderRow l = if null l then [] else [toRow l] + hdrs = toHeaderRow r + rows = map toRow rs aligns = replicate numcols AlignDefault - widths = replicate numcols 0 + widths = replicate numcols ColWidthDefault Right [] -> return $ B.doc mempty Left e -> throwError $ PandocParsecError s e diff --git a/src/Text/Pandoc/Readers/CommonMark.hs b/src/Text/Pandoc/Readers/CommonMark.hs index 67853aef7..d1f732bf1 100644 --- a/src/Text/Pandoc/Readers/CommonMark.hs +++ b/src/Text/Pandoc/Readers/CommonMark.hs @@ -111,31 +111,39 @@ addBlock opts (Node _ (LIST listAttrs) nodes) = PAREN_DELIM -> OneParen exts = readerExtensions opts addBlock opts (Node _ (TABLE alignments) nodes) = - (Table [] aligns widths headers rows :) + (Table + nullAttr + (Caption Nothing []) + (zip aligns widths) + (TableHead nullAttr headers) + [TableBody nullAttr 0 [] rows] + (TableFoot nullAttr []) :) where aligns = map fromTableCellAlignment alignments fromTableCellAlignment NoAlignment = AlignDefault fromTableCellAlignment LeftAligned = AlignLeft fromTableCellAlignment RightAligned = AlignRight fromTableCellAlignment CenterAligned = AlignCenter - widths = replicate numcols 0.0 + widths = replicate numcols ColWidthDefault numcols = if null rows' then 0 - else maximum $ map length rows' + else maximum $ map rowLength rows' rows' = map toRow $ filter isRow nodes (headers, rows) = case rows' of - (h:rs) -> (h, rs) + (h:rs) -> ([h], rs) [] -> ([], []) isRow (Node _ TABLE_ROW _) = True isRow _ = False isCell (Node _ TABLE_CELL _) = True isCell _ = False - toRow (Node _ TABLE_ROW ns) = map toCell $ filter isCell ns + toRow (Node _ TABLE_ROW ns) = Row nullAttr $ map toCell $ filter isCell ns toRow (Node _ t _) = error $ "toRow encountered non-row " ++ show t - toCell (Node _ TABLE_CELL []) = [] + toCell (Node _ TABLE_CELL []) = fromSimpleCell [] toCell (Node _ TABLE_CELL (n:ns)) - | isBlockNode n = addBlocks opts (n:ns) - | otherwise = [Plain (addInlines opts (n:ns))] + | isBlockNode n = fromSimpleCell $ addBlocks opts (n:ns) + | otherwise = fromSimpleCell [Plain (addInlines opts (n:ns))] toCell (Node _ t _) = error $ "toCell encountered non-cell " ++ show t + fromSimpleCell = Cell nullAttr AlignDefault 1 1 + rowLength (Row _ body) = length body -- all cells are 1×1 addBlock _ (Node _ TABLE_ROW _) = id -- handled in TABLE addBlock _ (Node _ TABLE_CELL _) = id -- handled in TABLE addBlock _ _ = id diff --git a/src/Text/Pandoc/Readers/DocBook.hs b/src/Text/Pandoc/Readers/DocBook.hs index 7f71cb3c1..9757b8914 100644 --- a/src/Text/Pandoc/Readers/DocBook.hs +++ b/src/Text/Pandoc/Readers/DocBook.hs @@ -676,10 +676,10 @@ getMediaobject e = do Just z -> mconcat <$> mapM parseInline (elContent z) figTitle <- gets dbFigureTitle - let (caption, title) = if isNull figTitle - then (getCaption e, "") - else (return figTitle, "fig:") - fmap (imageWith attr imageUrl title) caption + let (capt, title) = if isNull figTitle + then (getCaption e, "") + else (return figTitle, "fig:") + fmap (imageWith attr imageUrl title) capt getBlocks :: PandocMonad m => Element -> DB m Blocks getBlocks e = mconcat <$> @@ -844,9 +844,9 @@ parseBlock (Elem e) = return (mconcat $ intersperse (str "; ") terms', items') parseTable = do let isCaption x = named "title" x || named "caption" x - caption <- case filterChild isCaption e of - Just t -> getInlines t - Nothing -> return mempty + capt <- case filterChild isCaption e of + Just t -> getInlines t + Nothing -> return mempty let e' = fromMaybe e $ filterChild (named "tgroup") e let isColspec x = named "colspec" x || named "col" x let colspecs = case filterChild (named "colgroup") e' of @@ -868,12 +868,12 @@ parseBlock (Elem e) = Just "right" -> AlignRight Just "center" -> AlignCenter _ -> AlignDefault - let toWidth c = case findAttr (unqual "colwidth") c of - Just w -> fromMaybe 0 - $ safeRead $ "0" <> T.filter (\x -> + let toWidth c = do + w <- findAttr (unqual "colwidth") c + n <- safeRead $ "0" <> T.filter (\x -> (x >= '0' && x <= '9') || x == '.') (T.pack w) - Nothing -> 0 :: Double + if n > 0 then Just n else Nothing let numrows = case bodyrows of [] -> 0 xs -> maximum $ map length xs @@ -881,17 +881,19 @@ parseBlock (Elem e) = [] -> replicate numrows AlignDefault cs -> map toAlignment cs let widths = case colspecs of - [] -> replicate numrows 0 - cs -> let ws = map toWidth cs - tot = sum ws - in if all (> 0) ws - then map (/ tot) ws - else replicate numrows 0 - let headrows' = if null headrows - then replicate numrows mempty - else headrows - return $ table caption (zip aligns widths) - headrows' bodyrows + [] -> replicate numrows ColWidthDefault + cs -> let ws = map toWidth cs + in case sequence ws of + Just ws' -> let tot = sum ws' + in ColWidth . (/ tot) <$> ws' + Nothing -> replicate numrows ColWidthDefault + let toRow = Row nullAttr . map simpleCell + toHeaderRow l = if null l then [] else [toRow l] + return $ table (simpleCaption $ plain capt) + (zip aligns widths) + (TableHead nullAttr $ toHeaderRow headrows) + [TableBody nullAttr 0 [] $ map toRow bodyrows] + (TableFoot nullAttr []) isEntry x = named "entry" x || named "td" x || named "th" x parseRow = mapM (parseMixed plain . elContent) . filterChildren isEntry sect n = do isbook <- gets dbBook diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index f616a5b7a..bb86c91b0 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -72,12 +72,12 @@ import Data.Maybe (isJust, fromMaybe) import Data.Sequence (ViewL (..), viewl) import qualified Data.Sequence as Seq import qualified Data.Set as Set -import Text.Pandoc.Builder +import Text.Pandoc.Builder as Pandoc import Text.Pandoc.MediaBag (MediaBag) import Text.Pandoc.Options import Text.Pandoc.Readers.Docx.Combine import Text.Pandoc.Readers.Docx.Lists -import Text.Pandoc.Readers.Docx.Parse +import Text.Pandoc.Readers.Docx.Parse as Docx import Text.Pandoc.Shared import Text.Pandoc.Walk import Text.TeXMath (writeTeX) @@ -494,13 +494,13 @@ singleParaToPlain blks singleton $ Plain ils singleParaToPlain blks = blks -cellToBlocks :: PandocMonad m => Cell -> DocxContext m Blocks -cellToBlocks (Cell bps) = do +cellToBlocks :: PandocMonad m => Docx.Cell -> DocxContext m Blocks +cellToBlocks (Docx.Cell bps) = do blks <- smushBlocks <$> mapM bodyPartToBlocks bps return $ fromList $ blocksToDefinitions $ blocksToBullets $ toList blks -rowToBlocksList :: PandocMonad m => Row -> DocxContext m [Blocks] -rowToBlocksList (Row cells) = do +rowToBlocksList :: PandocMonad m => Docx.Row -> DocxContext m [Blocks] +rowToBlocksList (Docx.Row cells) = do blksList <- mapM cellToBlocks cells return $ map singleParaToPlain blksList @@ -645,7 +645,7 @@ bodyPartToBlocks (ListItem pPr _ _ _ parparts) = bodyPartToBlocks (Tbl _ _ _ []) = return $ para mempty bodyPartToBlocks (Tbl cap _ look parts@(r:rs)) = do - let caption = text cap + let cap' = simpleCaption $ plain $ text cap (hdr, rows) = case firstRowFormatting look of True | null rs -> (Nothing, [r]) | otherwise -> (Just r, rs) @@ -659,16 +659,19 @@ bodyPartToBlocks (Tbl cap _ look parts@(r:rs)) = do -- https://github.com/jgm/pandoc/pull/4361#issuecomment-365416155 nonEmpty [] = Nothing nonEmpty l = Just l - rowLength :: Row -> Int - rowLength (Row c) = length c + rowLength :: Docx.Row -> Int + rowLength (Docx.Row c) = length c + + let toRow = Pandoc.Row nullAttr . map simpleCell + toHeaderRow l = if null l then [] else [toRow l] -- pad cells. New Text.Pandoc.Builder will do that for us, -- so this is for compatibility while we switch over. - let cells' = map (\row -> take width (row ++ repeat mempty)) cells + let cells' = map (\row -> toRow $ take width (row ++ repeat mempty)) cells hdrCells <- case hdr of - Just r' -> rowToBlocksList r' - Nothing -> return $ replicate width mempty + Just r' -> toHeaderRow <$> rowToBlocksList r' + Nothing -> return [] -- The two following variables (horizontal column alignment and -- relative column widths) go to the default at the @@ -676,9 +679,13 @@ bodyPartToBlocks (Tbl cap _ look parts@(r:rs)) = do -- so should be possible. Alignment might be more difficult, -- since there doesn't seem to be a column entity in docx. let alignments = replicate width AlignDefault - widths = replicate width 0 :: [Double] + widths = replicate width ColWidthDefault - return $ table caption (zip alignments widths) hdrCells cells' + return $ table cap' + (zip alignments widths) + (TableHead nullAttr hdrCells) + [TableBody nullAttr 0 [] cells'] + (TableFoot nullAttr []) bodyPartToBlocks (OMathPara e) = return $ para $ displayMath (writeTeX e) diff --git a/src/Text/Pandoc/Readers/DokuWiki.hs b/src/Text/Pandoc/Readers/DokuWiki.hs index 384deb694..8b48789b3 100644 --- a/src/Text/Pandoc/Readers/DokuWiki.hs +++ b/src/Text/Pandoc/Readers/DokuWiki.hs @@ -470,8 +470,14 @@ table = do let (headerRow, body) = if firstSeparator == '^' then (head rows, tail rows) else ([], rows) - let attrs = (AlignDefault, 0.0) <$ transpose rows - pure $ B.table mempty attrs headerRow body + let attrs = (AlignDefault, ColWidthDefault) <$ transpose rows + let toRow = Row nullAttr . map B.simpleCell + toHeaderRow l = if null l then [] else [toRow l] + pure $ B.table B.emptyCaption + attrs + (TableHead nullAttr $ toHeaderRow headerRow) + [TableBody nullAttr 0 [] $ map toRow body] + (TableFoot nullAttr []) tableRows :: PandocMonad m => DWParser m [[B.Blocks]] tableRows = many1 tableRow diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs index 798661fe3..a48836446 100644 --- a/src/Text/Pandoc/Readers/HTML.hs +++ b/src/Text/Pandoc/Readers/HTML.hs @@ -513,12 +513,18 @@ pTable = try $ do _ -> replicate cols AlignDefault let widths = if null widths' then if isSimple - then replicate cols 0 - else replicate cols (1.0 / fromIntegral cols) + then replicate cols ColWidthDefault + else replicate cols (ColWidth (1.0 / fromIntegral cols)) else widths' - return $ B.table caption (zip aligns widths) head' rows - -pCol :: PandocMonad m => TagParser m Double + let toRow = Row nullAttr . map B.simpleCell + toHeaderRow l = if null l then [] else [toRow l] + return $ B.table (B.simpleCaption $ B.plain caption) + (zip aligns widths) + (TableHead nullAttr $ toHeaderRow head') + [TableBody nullAttr 0 [] $ map toRow rows] + (TableFoot nullAttr []) + +pCol :: PandocMonad m => TagParser m ColWidth pCol = try $ do TagOpen _ attribs' <- pSatisfy (matchTagOpen "col" []) let attribs = toStringAttr attribs' @@ -535,10 +541,10 @@ pCol = try $ do fromMaybe 0.0 $ safeRead xs _ -> 0.0 if width > 0.0 - then return $ width / 100.0 - else return 0.0 + then return $ ColWidth $ width / 100.0 + else return ColWidthDefault -pColgroup :: PandocMonad m => TagParser m [Double] +pColgroup :: PandocMonad m => TagParser m [ColWidth] pColgroup = try $ do pSatisfy (matchTagOpen "colgroup" []) skipMany pBlank diff --git a/src/Text/Pandoc/Readers/Haddock.hs b/src/Text/Pandoc/Readers/Haddock.hs index 749a63114..8fe5e062c 100644 --- a/src/Text/Pandoc/Readers/Haddock.hs +++ b/src/Text/Pandoc/Readers/Haddock.hs @@ -85,14 +85,20 @@ docHToBlocks d' = , tableBodyRows = bodyRows } -> let toCells = map (docHToBlocks . tableCellContents) . tableRowCells + toRow = Row nullAttr . map B.simpleCell + toHeaderRow l = if null l then [] else [toRow l] (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 + (AlignDefault, ColWidthDefault) + in B.table B.emptyCaption + colspecs + (TableHead nullAttr $ toHeaderRow header) + [TableBody nullAttr 0 [] $ map toRow body] + (TableFoot nullAttr []) where inlineFallback = B.plain $ docHToInlines False d' consolidatePlains = B.fromList . consolidatePlains' . B.toList diff --git a/src/Text/Pandoc/Readers/Ipynb.hs b/src/Text/Pandoc/Readers/Ipynb.hs index bfd9572ce..079eacf97 100644 --- a/src/Text/Pandoc/Readers/Ipynb.hs +++ b/src/Text/Pandoc/Readers/Ipynb.hs @@ -69,7 +69,7 @@ notebookToPandoc opts notebook = do return $ Pandoc (Meta $ M.insert "jupyter" (MetaMap m) mempty) blocks cellToBlocks :: PandocMonad m - => ReaderOptions -> Text -> Cell a -> m B.Blocks + => ReaderOptions -> Text -> Ipynb.Cell a -> m B.Blocks cellToBlocks opts lang c = do let Source ts = cellSource c let source = mconcat ts diff --git a/src/Text/Pandoc/Readers/JATS.hs b/src/Text/Pandoc/Readers/JATS.hs index 3672b05f6..f78630ec0 100644 --- a/src/Text/Pandoc/Readers/JATS.hs +++ b/src/Text/Pandoc/Readers/JATS.hs @@ -134,14 +134,14 @@ getGraphic :: PandocMonad m => Maybe (Inlines, Text) -> Element -> JATS m Inlines getGraphic mbfigdata e = do let atVal a = attrValue a e - (ident, title, caption) = + (ident, title, capt) = case mbfigdata of - Just (capt, i) -> (i, "fig:" <> atVal "title", capt) + Just (capt', i) -> (i, "fig:" <> atVal "title", capt') Nothing -> (atVal "id", atVal "title", text (atVal "alt-text")) attr = (ident, T.words $ atVal "role", []) imageUrl = atVal "href" - return $ imageWith attr imageUrl title caption + return $ imageWith attr imageUrl title capt getBlocks :: PandocMonad m => Element -> JATS m Blocks getBlocks e = mconcat <$> @@ -230,20 +230,20 @@ parseBlock (Elem e) = -- implicit figure. otherwise, we emit a div with the contents case filterChildren (named "graphic") e of [g] -> do - caption <- case filterChild (named "caption") e of - Just t -> mconcat . - intersperse linebreak <$> - mapM getInlines - (filterChildren (const True) t) - Nothing -> return mempty - img <- getGraphic (Just (caption, attrValue "id" e)) g + capt <- case filterChild (named "caption") e of + Just t -> mconcat . + intersperse linebreak <$> + mapM getInlines + (filterChildren (const True) t) + Nothing -> return mempty + img <- getGraphic (Just (capt, attrValue "id" e)) g return $ para img _ -> divWith (attrValue "id" e, ["fig"], []) <$> getBlocks e parseTable = do let isCaption x = named "title" x || named "caption" x - caption <- case filterChild isCaption e of - Just t -> getInlines t - Nothing -> return mempty + capt <- case filterChild isCaption e of + Just t -> getInlines t + Nothing -> return mempty let e' = fromMaybe e $ filterChild (named "tgroup") e let isColspec x = named "colspec" x || named "col" x let colspecs = case filterChild (named "colgroup") e' of @@ -265,27 +265,28 @@ parseBlock (Elem e) = Just "right" -> AlignRight Just "center" -> AlignCenter _ -> AlignDefault - let toWidth c = case findAttrText (unqual "colwidth") c of - Just w -> fromMaybe 0 - $ safeRead $ "0" <> T.filter (\x -> - isDigit x || x == '.') w - Nothing -> 0 :: Double + let toWidth c = do + w <- findAttrText (unqual "colwidth") c + n <- safeRead $ "0" <> T.filter (\x -> isDigit x || x == '.') w + if n > 0 then Just n else Nothing let numrows = foldl' max 0 $ map length bodyrows let aligns = case colspecs of [] -> replicate numrows AlignDefault cs -> map toAlignment cs let widths = case colspecs of - [] -> replicate numrows 0 - cs -> let ws = map toWidth cs - tot = sum ws - in if all (> 0) ws - then map (/ tot) ws - else replicate numrows 0 - let headrows' = if null headrows - then replicate numrows mempty - else headrows - return $ table caption (zip aligns widths) - headrows' bodyrows + [] -> replicate numrows ColWidthDefault + cs -> let ws = map toWidth cs + in case sequence ws of + Just ws' -> let tot = sum ws' + in ColWidth . (/ tot) <$> ws' + Nothing -> replicate numrows ColWidthDefault + let toRow = Row nullAttr . map simpleCell + toHeaderRow l = if null l then [] else [toRow l] + return $ table (simpleCaption $ plain capt) + (zip aligns widths) + (TableHead nullAttr $ toHeaderRow headrows) + [TableBody nullAttr 0 [] $ map toRow bodyrows] + (TableFoot nullAttr []) isEntry x = named "entry" x || named "td" x || named "th" x parseRow = mapM (parseMixed plain . elContent) . filterChildren isEntry sect n = do isbook <- gets jatsBook diff --git a/src/Text/Pandoc/Readers/Jira.hs b/src/Text/Pandoc/Readers/Jira.hs index d0900fd08..fd96cbc4d 100644 --- a/src/Text/Pandoc/Readers/Jira.hs +++ b/src/Text/Pandoc/Readers/Jira.hs @@ -16,7 +16,7 @@ import Data.Text (Text, append, pack, singleton, unpack) import Text.HTML.TagSoup.Entity (lookupEntity) import Text.Jira.Parser (parse) import Text.Pandoc.Class.PandocMonad (PandocMonad (..)) -import Text.Pandoc.Builder +import Text.Pandoc.Builder hiding (cell) import Text.Pandoc.Error (PandocError (PandocParseError)) import Text.Pandoc.Options (ReaderOptions) import Text.Pandoc.Shared (stringify) diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 038430f99..cdd2c1362 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -2268,7 +2268,7 @@ splitWordTok = do setInput $ map (Tok spos Symbol . T.singleton) (T.unpack t) <> rest _ -> return () -parseAligns :: PandocMonad m => LP m [(Alignment, Double, ([Tok], [Tok]))] +parseAligns :: PandocMonad m => LP m [(Alignment, ColWidth, ([Tok], [Tok]))] parseAligns = try $ do let maybeBar = skipMany (try $ sp *> (() <$ symbol '|' <|> () <$ (symbol '@' >> braced))) @@ -2289,17 +2289,15 @@ parseAligns = try $ do ds <- trim . untokenize <$> manyTill anyTok (controlSeq "linewidth") spaces symbol '}' - case safeRead ds of - Just w -> return w - Nothing -> return 0.0 + return $ safeRead ds let alignSpec = do pref <- option [] alignPrefix spaces al <- alignChar - width <- colWidth <|> option 0.0 (do s <- untokenize <$> braced - pos <- getPosition - report $ SkippedContent s pos - return 0.0) + width <- colWidth <|> option Nothing (do s <- untokenize <$> braced + pos <- getPosition + report $ SkippedContent s pos + return Nothing) spaces suff <- option [] alignSuffix return (al, width, (pref, suff)) @@ -2321,7 +2319,11 @@ parseAligns = try $ do spaces egroup spaces - return aligns' + return $ map toSpec aligns' + where + toColWidth (Just w) | w > 0 = ColWidth w + toColWidth _ = ColWidthDefault + toSpec (x, y, z) = (x, toColWidth y, z) parseTableRow :: PandocMonad m => Text -- ^ table environment name @@ -2370,7 +2372,6 @@ simpTable envname hasWidthParameter = try $ do skipopts colspecs <- parseAligns let (aligns, widths, prefsufs) = unzip3 colspecs - let cols = length colspecs optional $ controlSeq "caption" *> setCaption spaces optional label @@ -2391,19 +2392,22 @@ simpTable envname hasWidthParameter = try $ do spaces optional lbreak spaces - let header'' = if null header' - then replicate cols mempty - else header' lookAhead $ controlSeq "end" -- make sure we're at end - return $ table mempty (zip aligns widths) header'' rows + let toRow = Row nullAttr . map simpleCell + toHeaderRow l = if null l then [] else [toRow l] + return $ table emptyCaption + (zip aligns widths) + (TableHead nullAttr $ toHeaderRow header') + [TableBody nullAttr 0 [] $ map toRow rows] + (TableFoot nullAttr []) addTableCaption :: PandocMonad m => Blocks -> LP m Blocks addTableCaption = walkM go - where go (Table c als ws hs rs) = do + where go (Table attr c spec th tb tf) = do st <- getState let mblabel = sLastLabel st capt <- case (sCaption st, mblabel) of - (Just ils, Nothing) -> return $ toList ils + (Just ils, Nothing) -> return $ caption Nothing (plain ils) (Just ils, Just lab) -> do num <- getNextNumber sLastTableNum setState @@ -2411,13 +2415,12 @@ addTableCaption = walkM go , sLabels = M.insert lab [Str (renderDottedNum num)] (sLabels st) } - return $ toList ils -- add number?? + return $ caption Nothing (plain ils) -- add number?? (Nothing, _) -> return c return $ maybe id (\ident -> Div (ident, [], []) . (:[])) mblabel $ - Table capt als ws hs rs + Table attr capt spec th tb tf go x = return x - block :: PandocMonad m => LP m Blocks block = do res <- (mempty <$ spaces1) diff --git a/src/Text/Pandoc/Readers/Man.hs b/src/Text/Pandoc/Readers/Man.hs index c14cbea52..12001b534 100644 --- a/src/Text/Pandoc/Readers/Man.hs +++ b/src/Text/Pandoc/Readers/Man.hs @@ -107,11 +107,12 @@ parseTable = do bodyRows <- mapM (mapM parseTableCell . snd) bodyRows' isPlainTable <- tableCellsPlain <$> getState let widths = if isPlainTable - then repeat 0.0 - else repeat ((1.0 / fromIntegral (length alignments)) - :: Double) - return $ B.table mempty (zip alignments widths) - headerRow bodyRows) <|> fallback pos + then repeat ColWidthDefault + else repeat $ ColWidth (1.0 / fromIntegral (length alignments)) + return $ B.table B.emptyCaption (zip alignments widths) + (TableHead nullAttr $ toHeaderRow headerRow) + [TableBody nullAttr 0 [] $ map toRow bodyRows] + (TableFoot nullAttr [])) <|> fallback pos [] -> fallback pos where @@ -160,6 +161,8 @@ parseTable = do 'r' -> Just AlignRight _ -> Nothing + toRow = Row nullAttr . map simpleCell + toHeaderRow l = if null l then [] else [toRow l] parseNewParagraph :: PandocMonad m => ManParser m Blocks parseNewParagraph = do diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 66f4df341..72a0975fd 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -28,11 +28,11 @@ import qualified Data.Text as T import qualified Data.Text.Lazy as TL import qualified Data.ByteString.Lazy as BL import System.FilePath (addExtension, takeExtension) -import Text.HTML.TagSoup +import Text.HTML.TagSoup hiding (Row) import Text.Pandoc.Builder (Blocks, Inlines) import qualified Text.Pandoc.Builder as B import Text.Pandoc.Class.PandocMonad (PandocMonad (..), report) -import Text.Pandoc.Definition +import Text.Pandoc.Definition as Pandoc import Text.Pandoc.Emoji (emojiToInline) import Text.Pandoc.Error import Text.Pandoc.Logging @@ -1163,7 +1163,7 @@ simpleTableHeader headless = try $ do else return rawContent let aligns = zipWith alignType (map (: []) rawHeads) lengths let rawHeads' = if headless - then replicate (length dashes) "" + then [] else rawHeads heads <- fmap sequence $ @@ -1235,7 +1235,7 @@ tableCaption = try $ do -- Parse a simple table with '---' header and one line per row. simpleTable :: PandocMonad m => Bool -- ^ Headerless table - -> MarkdownParser m ([Alignment], [Double], F [Blocks], F [[Blocks]]) + -> MarkdownParser m ([Alignment], [Double], F [Row], F [Row]) simpleTable headless = do (aligns, _widths, heads', lines') <- tableWith (simpleTableHeader headless) tableLine @@ -1250,7 +1250,7 @@ simpleTable headless = do -- ending with a footer (dashed line followed by blank line). multilineTable :: PandocMonad m => Bool -- ^ Headerless table - -> MarkdownParser m ([Alignment], [Double], F [Blocks], F [[Blocks]]) + -> MarkdownParser m ([Alignment], [Double], F [Row], F [Row]) multilineTable headless = tableWith (multilineTableHeader headless) multilineRow blanklines tableFooter @@ -1281,7 +1281,7 @@ multilineTableHeader headless = try $ do rawContent let aligns = zipWith alignType rawHeadsList lengths let rawHeads = if headless - then replicate (length dashes) "" + then [] else map (T.unlines . map trim) rawHeadsList heads <- fmap sequence $ mapM (parseFromString' (mconcat <$> many plain).trim) rawHeads @@ -1292,7 +1292,7 @@ multilineTableHeader headless = try $ do -- which may be grid, separated by blank lines, and -- ending with a footer (dashed line followed by blank line). gridTable :: PandocMonad m => Bool -- ^ Headerless table - -> MarkdownParser m ([Alignment], [Double], F [Blocks], F [[Blocks]]) + -> MarkdownParser m ([Alignment], [Double], F [Row], F [Row]) gridTable headless = gridTableWith' parseBlocks headless pipeBreak :: PandocMonad m => MarkdownParser m ([Alignment], [Int]) @@ -1307,7 +1307,7 @@ pipeBreak = try $ do blankline return $ unzip (first:rest) -pipeTable :: PandocMonad m => MarkdownParser m ([Alignment], [Double], F [Blocks], F [[Blocks]]) +pipeTable :: PandocMonad m => MarkdownParser m ([Alignment], [Double], F [Row], F [Row]) pipeTable = try $ do nonindentSpaces lookAhead nonspaceChar @@ -1323,7 +1323,7 @@ pipeTable = try $ do fromIntegral len / fromIntegral (sum seplengths)) seplengths else replicate (length aligns) 0.0 - return (aligns, widths, heads', sequence lines'') + return (aligns, widths, toHeaderRow <$> heads', map toRow <$> sequence lines'') sepPipe :: PandocMonad m => MarkdownParser m () sepPipe = try $ do @@ -1384,7 +1384,7 @@ tableWith :: PandocMonad m -> ([Int] -> MarkdownParser m (F [Blocks])) -> MarkdownParser m sep -> MarkdownParser m end - -> MarkdownParser m ([Alignment], [Double], F [Blocks], F [[Blocks]]) + -> MarkdownParser m ([Alignment], [Double], F [Row], F [Row]) tableWith headerParser rowParser lineParser footerParser = try $ do (heads, aligns, indices) <- headerParser lines' <- fmap sequence $ rowParser indices `sepEndBy1` lineParser @@ -1393,7 +1393,7 @@ tableWith headerParser rowParser lineParser footerParser = try $ do let widths = if null indices then replicate (length aligns) 0.0 else widthsFromIndices numColumns indices - return (aligns, widths, heads, lines') + return (aligns, widths, toHeaderRow <$> heads, map toRow <$> lines') table :: PandocMonad m => MarkdownParser m (F Blocks) table = try $ do @@ -1417,11 +1417,18 @@ table = try $ do let widths' = if totalWidth < 1 then widths else map (/ totalWidth) widths + let strictPos w + | w > 0 = ColWidth w + | otherwise = ColWidthDefault return $ do caption' <- caption heads' <- heads lns' <- lns - return $ B.table caption' (zip aligns widths') heads' lns' + return $ B.table (B.simpleCaption $ B.plain caption') + (zip aligns (strictPos <$> widths')) + (TableHead nullAttr heads') + [TableBody nullAttr 0 [] lns'] + (TableFoot nullAttr []) -- -- inline @@ -2110,3 +2117,9 @@ doubleQuoted = try $ do withQuoteContext InDoubleQuote $ fmap B.doubleQuoted . trimInlinesF . mconcat <$> many1Till inline doubleQuoteEnd + +toRow :: [Blocks] -> Row +toRow = Row nullAttr . map B.simpleCell + +toHeaderRow :: [Blocks] -> [Row] +toHeaderRow l = if null l then [] else [toRow l] diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs index a2ff51379..6bcc4735e 100644 --- a/src/Text/Pandoc/Readers/MediaWiki.hs +++ b/src/Text/Pandoc/Readers/MediaWiki.hs @@ -221,9 +221,9 @@ table = do let restwidth = tableWidth - sum widths let zerocols = length $ filter (==0.0) widths let defaultwidth = if zerocols == 0 || zerocols == length widths - then 0.0 - else restwidth / fromIntegral zerocols - let widths' = map (\w -> if w == 0 then defaultwidth else w) widths + then ColWidthDefault + else ColWidth $ restwidth / fromIntegral zerocols + let widths' = map (\w -> if w > 0 then ColWidth w else defaultwidth) widths let cellspecs = zip (map fst cellspecs') widths' rows' <- many $ try $ rowsep *> (map snd <$> tableRow) optional blanklines @@ -232,7 +232,13 @@ table = do let (headers,rows) = if hasheader then (hdr, rows') else (replicate cols mempty, hdr:rows') - return $ B.table caption cellspecs headers rows + let toRow = Row nullAttr . map B.simpleCell + toHeaderRow l = if null l then [] else [toRow l] + return $ B.table (B.simpleCaption $ B.plain caption) + cellspecs + (TableHead nullAttr $ toHeaderRow headers) + [TableBody nullAttr 0 [] $ map toRow rows] + (TableFoot nullAttr []) parseAttrs :: PandocMonad m => MWParser m [(Text,Text)] parseAttrs = many1 parseAttr diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs index a5def2479..987028910 100644 --- a/src/Text/Pandoc/Readers/Muse.hs +++ b/src/Text/Pandoc/Readers/Muse.hs @@ -645,9 +645,15 @@ data MuseTableElement = MuseHeaderRow [Blocks] museToPandocTable :: MuseTable -> Blocks museToPandocTable (MuseTable caption headers body footers) = - B.table caption attrs headRow (rows ++ body ++ footers) - where attrs = (AlignDefault, 0.0) <$ transpose (headers ++ body ++ footers) + B.table (B.simpleCaption $ B.plain caption) + attrs + (TableHead nullAttr $ toHeaderRow headRow) + [TableBody nullAttr 0 [] $ map toRow $ rows ++ body ++ footers] + (TableFoot nullAttr []) + where attrs = (AlignDefault, ColWidthDefault) <$ transpose (headers ++ body ++ footers) (headRow, rows) = fromMaybe ([], []) $ uncons headers + toRow = Row nullAttr . map B.simpleCell + toHeaderRow l = if null l then [] else [toRow l] museAppendElement :: MuseTableElement -> MuseTable @@ -693,8 +699,13 @@ museGridTable = try $ do indent <- getIndent indices <- museGridTableHeader fmap rowsToTable . sequence <$> many1 (museGridTableRow indent indices) - where rowsToTable rows = B.table mempty attrs [] rows - where attrs = (AlignDefault, 0.0) <$ transpose rows + where rowsToTable rows = B.table B.emptyCaption + attrs + (TableHead nullAttr []) + [TableBody nullAttr 0 [] $ map toRow rows] + (TableFoot nullAttr []) + where attrs = (AlignDefault, ColWidthDefault) <$ transpose rows + toRow = Row nullAttr . map B.simpleCell -- | Parse a table. table :: PandocMonad m => MuseParser m (F Blocks) diff --git a/src/Text/Pandoc/Readers/Odt/ContentReader.hs b/src/Text/Pandoc/Readers/Odt/ContentReader.hs index 69c8e2924..cbf7236d0 100644 --- a/src/Text/Pandoc/Readers/Odt/ContentReader.hs +++ b/src/Text/Pandoc/Readers/Odt/ContentReader.hs @@ -921,8 +921,8 @@ post_process (Pandoc m blocks) = Pandoc m (post_process' blocks) post_process' :: [Block] -> [Block] -post_process' (Table _ a w h r : Div ("", ["caption"], _) [Para inlines] : xs) = - Table inlines a w h r : post_process' xs +post_process' (Table attr _ specs th tb tf : Div ("", ["caption"], _) blks : xs) + = Table attr (Caption Nothing blks) specs th tb tf : post_process' xs post_process' bs = bs read_body :: OdtReader _x (Pandoc, MediaBag) diff --git a/src/Text/Pandoc/Readers/Org/Blocks.hs b/src/Text/Pandoc/Readers/Org/Blocks.hs index c80c179c6..b2cf3b3ec 100644 --- a/src/Text/Pandoc/Readers/Org/Blocks.hs +++ b/src/Text/Pandoc/Readers/Org/Blocks.hs @@ -627,16 +627,22 @@ orgToPandocTable (OrgTable colProps heads lns) caption = let totalWidth = if any (isJust . columnRelWidth) colProps then Just . sum $ map (fromMaybe 1 . columnRelWidth) colProps else Nothing - in B.table caption (map (convertColProp totalWidth) colProps) heads lns + in B.table (B.simpleCaption $ B.plain caption) + (map (convertColProp totalWidth) colProps) + (TableHead nullAttr $ toHeaderRow heads) + [TableBody nullAttr 0 [] $ map toRow lns] + (TableFoot nullAttr []) where - convertColProp :: Maybe Int -> ColumnProperty -> (Alignment, Double) + toRow = Row nullAttr . map B.simpleCell + toHeaderRow l = if null l then [] else [toRow l] + convertColProp :: Maybe Int -> ColumnProperty -> (Alignment, ColWidth) convertColProp totalWidth colProp = let align' = fromMaybe AlignDefault $ columnAlignment colProp - width' = fromMaybe 0 $ (\w t -> (fromIntegral w / fromIntegral t)) - <$> columnRelWidth colProp - <*> totalWidth - in (align', width') + width' = (\w t -> (fromIntegral w / fromIntegral t)) + <$> columnRelWidth colProp + <*> totalWidth + in (align', maybe ColWidthDefault ColWidth width') tableRows :: PandocMonad m => OrgParser m [OrgTableRow] tableRows = try $ many (tableAlignRow <|> tableHline <|> tableContentRow) @@ -658,16 +664,16 @@ tableAlignRow = try $ do return $ OrgAlignRow colProps columnPropertyCell :: Monad m => OrgParser m ColumnProperty -columnPropertyCell = emptyCell <|> propCell <?> "alignment info" +columnPropertyCell = emptyOrgCell <|> propCell <?> "alignment info" where - emptyCell = ColumnProperty Nothing Nothing <$ try (skipSpaces *> endOfCell) + emptyOrgCell = ColumnProperty Nothing Nothing <$ try (skipSpaces *> endOfCell) propCell = try $ ColumnProperty <$> (skipSpaces *> char '<' *> optionMaybe tableAlignFromChar) <*> (optionMaybe (many1Char digit >>= safeRead) <* char '>' - <* emptyCell) + <* emptyOrgCell) tableAlignFromChar :: Monad m => OrgParser m Alignment tableAlignFromChar = try $ diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index 430d24f4a..4acdc10c2 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -770,24 +770,34 @@ tableDirective :: PandocMonad m tableDirective top fields body = do bs <- parseFromString' parseBlocks body case B.toList bs of - [Table _ aligns' widths' header' rows'] -> do + [Table attr _ tspecs' thead@(TableHead _ thrs) tbody tfoot] -> do + let (aligns', widths') = unzip tspecs' title <- parseFromString' (trimInlines . mconcat <$> many inline) top columns <- getOption readerColumns - let numOfCols = length header' + let numOfCols = case thrs of + [] -> 0 + (r:_) -> rowLength r let normWidths ws = - map (/ max 1.0 (fromIntegral (columns - numOfCols))) ws + strictPos . (/ max 1.0 (fromIntegral (columns - numOfCols))) <$> ws let widths = case trim <$> lookup "widths" fields of - Just "auto" -> replicate numOfCols 0.0 + Just "auto" -> replicate numOfCols ColWidthDefault Just "grid" -> widths' Just specs -> normWidths $ map (fromMaybe (0 :: Double) . safeRead) $ splitTextBy (`elem` (" ," :: String)) specs Nothing -> widths' -- align is not applicable since we can't represent whole table align - return $ B.singleton $ Table (B.toList title) - aligns' widths header' rows' + let tspecs = zip aligns' widths + return $ B.singleton $ Table attr (B.caption Nothing (B.plain title)) + tspecs thead tbody tfoot _ -> return mempty - + where + -- only valid on the very first row of a table section + rowLength (Row _ rb) = sum $ cellLength <$> rb + cellLength (Cell _ _ _ (ColSpan w) _) = max 1 w + strictPos w + | w > 0 = ColWidth w + | otherwise = ColWidthDefault -- TODO: :stub-columns:. -- Only the first row becomes the header even if header-rows: > 1, @@ -808,19 +818,25 @@ listTableDirective top fields body = do else ([], rows, length x) _ -> ([],[],0) widths = case trim <$> lookup "widths" fields of - Just "auto" -> replicate numOfCols 0 + Just "auto" -> replicate numOfCols ColWidthDefault Just specs -> normWidths $ map (fromMaybe (0 :: Double) . safeRead) $ splitTextBy (`elem` (" ," :: String)) specs - _ -> replicate numOfCols 0 - return $ B.table title + _ -> replicate numOfCols ColWidthDefault + toRow = Row nullAttr . map B.simpleCell + toHeaderRow l = if null l then [] else [toRow l] + return $ B.table (B.simpleCaption $ B.plain title) (zip (replicate numOfCols AlignDefault) widths) - headerRow - bodyRows + (TableHead nullAttr $ toHeaderRow headerRow) + [TableBody nullAttr 0 [] $ map toRow bodyRows] + (TableFoot nullAttr []) where takeRows [BulletList rows] = map takeCells rows takeRows _ = [] takeCells [BulletList cells] = map B.fromList cells takeCells _ = [] - normWidths ws = map (/ max 1 (sum ws)) ws + normWidths ws = strictPos . (/ max 1 (sum ws)) <$> ws + strictPos w + | w > 0 = ColWidth w + | otherwise = ColWidthDefault csvTableDirective :: PandocMonad m => Text -> [(Text, Text)] -> Text @@ -873,18 +889,24 @@ csvTableDirective top fields rawcsv = do else ([], rows, length x) _ -> ([],[],0) title <- parseFromString' (trimInlines . mconcat <$> many inline) top - let normWidths ws = map (/ max 1 (sum ws)) ws + let strictPos w + | w > 0 = ColWidth w + | otherwise = ColWidthDefault + let normWidths ws = strictPos . (/ max 1 (sum ws)) <$> ws let widths = case trim <$> lookup "widths" fields of - Just "auto" -> replicate numOfCols 0 + Just "auto" -> replicate numOfCols ColWidthDefault Just specs -> normWidths $ map (fromMaybe (0 :: Double) . safeRead) $ splitTextBy (`elem` (" ," :: String)) specs - _ -> replicate numOfCols 0 - return $ B.table title - (zip (replicate numOfCols AlignDefault) widths) - headerRow - bodyRows + _ -> replicate numOfCols ColWidthDefault + let toRow = Row nullAttr . map B.simpleCell + toHeaderRow l = if null l then [] else [toRow l] + return $ B.table (B.simpleCaption $ B.plain title) + (zip (replicate numOfCols AlignDefault) widths) + (TableHead nullAttr $ toHeaderRow headerRow) + [TableBody nullAttr 0 [] $ map toRow bodyRows] + (TableFoot nullAttr []) -- TODO: -- - Only supports :format: fields with a single format for :raw: roles, @@ -1293,13 +1315,14 @@ simpleTable headless = do sep simpleTableFooter -- Simple tables get 0s for relative column widths (i.e., use default) case B.toList tbl of - [Table c a _w h l] -> return $ B.singleton $ - Table c a (replicate (length a) 0) h l + [Table attr cap spec th tb tf] -> return $ B.singleton $ + Table attr cap (rewidth spec) th tb tf _ -> throwError $ PandocShouldNeverHappenError "tableWith returned something unexpected" where sep = return () -- optional (simpleTableSep '-') + rewidth = fmap $ fmap $ const ColWidthDefault gridTable :: PandocMonad m => Bool -- ^ Headerless table diff --git a/src/Text/Pandoc/Readers/TWiki.hs b/src/Text/Pandoc/Readers/TWiki.hs index ee6a80ce3..4df1de045 100644 --- a/src/Text/Pandoc/Readers/TWiki.hs +++ b/src/Text/Pandoc/Readers/TWiki.hs @@ -228,12 +228,18 @@ table = try $ do return $ buildTable mempty rows $ fromMaybe (align rows, columns rows) tableHead where buildTable caption rows (aligns, heads) - = B.table caption aligns heads rows - align rows = replicate (columCount rows) (AlignDefault, 0) + = B.table (B.simpleCaption $ B.plain caption) + aligns + (TableHead nullAttr $ toHeaderRow heads) + [TableBody nullAttr 0 [] $ map toRow rows] + (TableFoot nullAttr []) + align rows = replicate (columCount rows) (AlignDefault, ColWidthDefault) columns rows = replicate (columCount rows) mempty columCount rows = length $ head rows + toRow = Row nullAttr . map B.simpleCell + toHeaderRow l = if null l then [] else [toRow l] -tableParseHeader :: PandocMonad m => TWParser m ((Alignment, Double), B.Blocks) +tableParseHeader :: PandocMonad m => TWParser m ((Alignment, ColWidth), B.Blocks) tableParseHeader = try $ do char '|' leftSpaces <- length <$> many spaceChar @@ -245,9 +251,9 @@ tableParseHeader = try $ do return (tableAlign leftSpaces rightSpaces, content) where tableAlign left right - | left >= 2 && left == right = (AlignCenter, 0) - | left > right = (AlignRight, 0) - | otherwise = (AlignLeft, 0) + | left >= 2 && left == right = (AlignCenter, ColWidthDefault) + | left > right = (AlignRight, ColWidthDefault) + | otherwise = (AlignLeft, ColWidthDefault) tableParseRow :: PandocMonad m => TWParser m [B.Blocks] tableParseRow = many1Till tableParseColumn newline diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs index 5aae11751..fef192fd3 100644 --- a/src/Text/Pandoc/Readers/Textile.hs +++ b/src/Text/Pandoc/Readers/Textile.hs @@ -377,10 +377,13 @@ table = try $ do _ -> (mempty, rawrows) let nbOfCols = maximum $ map length (headers:rows) let aligns = map minimum $ transpose $ map (map (snd . fst)) (headers:rows) - return $ B.table caption - (zip aligns (replicate nbOfCols 0.0)) - (map snd headers) - (map (map snd) rows) + let toRow = Row nullAttr . map B.simpleCell + toHeaderRow l = if null l then [] else [toRow l] + return $ B.table (B.simpleCaption $ B.plain caption) + (zip aligns (replicate nbOfCols ColWidthDefault)) + (TableHead nullAttr $ toHeaderRow $ map snd headers) + [TableBody nullAttr 0 [] $ map (toRow . map snd) rows] + (TableFoot nullAttr []) -- | Ignore markers for cols, thead, tfoot. ignorableRow :: PandocMonad m => ParserT Text ParserState m () diff --git a/src/Text/Pandoc/Readers/Txt2Tags.hs b/src/Text/Pandoc/Readers/Txt2Tags.hs index 68ba6dd7a..c5c87e471 100644 --- a/src/Text/Pandoc/Readers/Txt2Tags.hs +++ b/src/Text/Pandoc/Readers/Txt2Tags.hs @@ -267,9 +267,13 @@ table = try $ do let size = maximum (map length rows') let rowsPadded = map (pad size) rows' let headerPadded = if null tableHeader then mempty else pad size tableHeader - return $ B.table mempty - (zip aligns (replicate ncolumns 0.0)) - headerPadded rowsPadded + let toRow = Row nullAttr . map B.simpleCell + toHeaderRow l = if null l then [] else [toRow l] + return $ B.table B.emptyCaption + (zip aligns (replicate ncolumns ColWidthDefault)) + (TableHead nullAttr $ toHeaderRow headerPadded) + [TableBody nullAttr 0 [] $ map toRow rowsPadded] + (TableFoot nullAttr []) pad :: (Monoid a) => Int -> [a] -> [a] pad n xs = xs ++ replicate (n - length xs) mempty |