From 7cf4d41fe556cffafdc89ffa83fef65211fee477 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 12 Sep 2026 20:02:41 -0700 Subject: [PATCH] Use compactifyTable for tables produced by all readers. Remove old ad hoc `paraToPlain` at the table cell level. This should ensure that we don't get tables that mix Plain and Para. Such tables tend to look funny when rendered in docx and other formats. Closes #11864. --- src/Text/Pandoc/Parsing/GridTable.hs | 8 +- src/Text/Pandoc/Readers/AsciiDoc.hs | 8 +- src/Text/Pandoc/Readers/Djot.hs | 5 +- src/Text/Pandoc/Readers/Docx.hs | 14 +- src/Text/Pandoc/Readers/DokuWiki.hs | 5 +- src/Text/Pandoc/Readers/LaTeX/Table.hs | 16 +- src/Text/Pandoc/Readers/Man.hs | 5 +- src/Text/Pandoc/Readers/Markdown.hs | 2 +- src/Text/Pandoc/Readers/MediaWiki.hs | 5 +- src/Text/Pandoc/Readers/Muse.hs | 3 +- src/Text/Pandoc/Readers/ODT/ContentReader.hs | 4 +- src/Text/Pandoc/Readers/Org/Blocks.hs | 9 +- src/Text/Pandoc/Readers/RST.hs | 16 +- src/Text/Pandoc/Readers/TWiki.hs | 5 +- src/Text/Pandoc/Readers/Textile.hs | 5 +- src/Text/Pandoc/Readers/Txt2Tags.hs | 5 +- src/Text/Pandoc/Readers/Typst.hs | 18 +- test/asciidoc-reader.native | 174 ++++----- test/command/10390.md | 4 +- test/command/10490.md | 32 +- test/command/1166.md | 12 +- test/command/2606.md | 4 +- test/command/2649.md | 30 +- test/command/6549.md | 6 +- test/command/6992.md | 10 +- test/command/8110.md | 18 +- test/command/8659.md | 8 +- test/docx/golden/table_with_list_cell.docx | Bin 10957 -> 10951 bytes test/docx/table_with_list_cell.native | 4 +- test/markdown-reader-more.native | 2 +- test/mediawiki-reader.native | 78 ++-- test/rst-reader.native | 2 +- test/typst-reader.native | 390 +++++++++---------- 33 files changed, 447 insertions(+), 460 deletions(-) diff --git a/src/Text/Pandoc/Parsing/GridTable.hs b/src/Text/Pandoc/Parsing/GridTable.hs index 43871ef0f..50d72a154 100644 --- a/src/Text/Pandoc/Parsing/GridTable.hs +++ b/src/Text/Pandoc/Parsing/GridTable.hs @@ -39,7 +39,6 @@ import Text.Pandoc.Parsing.Capabilities import Text.Pandoc.Parsing.General import Text.Pandoc.Sources import Text.Parsec (Stream (..), ParsecT, optional, sepEndBy1, try) - import Data.Maybe (mapMaybe) import qualified Data.Text as T import qualified Text.GridTable as GT @@ -145,7 +144,7 @@ gridTableWith' normalization blocks = do tbl let rows = GT.rows blkTbl let toPandocCell (GT.Cell c (GT.RowSpan rs) (GT.ColSpan cs)) = - fmap (B.cell AlignDefault (B.RowSpan rs) (B.ColSpan cs) . plainify) <$> c + fmap (B.cell AlignDefault (B.RowSpan rs) (B.ColSpan cs)) <$> c rows' <- mapM (mapM toPandocCell) rows columns <- getOption readerColumns let colspecs = zipWith (\cs w -> (convAlign $ fst cs, B.ColWidth w)) @@ -187,11 +186,6 @@ removeOneLeadingSpace xs = Nothing -> True Just (c, _) -> c == ' ' -plainify :: B.Blocks -> B.Blocks -plainify blks = case B.toList blks of - [Para x] -> B.fromList [Plain x] - _ -> blks - convAlign :: GT.Alignment -> B.Alignment convAlign GT.AlignLeft = B.AlignLeft convAlign GT.AlignRight = B.AlignRight diff --git a/src/Text/Pandoc/Readers/AsciiDoc.hs b/src/Text/Pandoc/Readers/AsciiDoc.hs index 965e47fa1..01346920d 100644 --- a/src/Text/Pandoc/Readers/AsciiDoc.hs +++ b/src/Text/Pandoc/Readers/AsciiDoc.hs @@ -25,7 +25,7 @@ import Text.Pandoc.Options import Text.Pandoc.Definition import Text.Pandoc.Walk import Text.Pandoc.Shared (addPandocAttributes, blocksToInlines, safeRead, - tshow) + tshow, compactifyTable) import qualified Text.Pandoc.UTF8 as UTF8 import qualified AsciiDoc as A import Text.Pandoc.Error @@ -184,7 +184,8 @@ addBlockTitle tit' bs = let tit = B.toList tit' in case B.toList bs of [B.Table attr _ colspecs thead tbody tfoot] -> - B.singleton $ B.Table attr (B.Caption Nothing [B.Plain tit]) + B.singleton $ compactifyTable + $ B.Table attr (B.Caption Nothing [B.Plain tit]) colspecs thead tbody tfoot [B.Figure attr _ bs'] -> B.singleton $ B.Figure attr (B.Caption Nothing [B.Plain tit]) bs' @@ -281,7 +282,8 @@ doBlock (A.Block attr@(A.Attr ps kvs) mbtitle bt) = do fromIntegral x / fromIntegral totalWidth)) (A.colWidth spec)) let colspecs = map toColSpec specs - pure $ B.table (B.Caption Nothing mempty) -- added by addBlockTitle + pure $ compactifyTable + $ B.table (B.Caption Nothing mempty) -- added by addBlockTitle colspecs thead [tbody] tfoot A.BlockImage target mbalt mbw mbh -> do img' <- doInline (A.Inline mempty (A.InlineImage target mbalt mbw mbh)) diff --git a/src/Text/Pandoc/Readers/Djot.hs b/src/Text/Pandoc/Readers/Djot.hs index 471d6a0c9..72222675d 100644 --- a/src/Text/Pandoc/Readers/Djot.hs +++ b/src/Text/Pandoc/Readers/Djot.hs @@ -25,7 +25,7 @@ import Text.Pandoc.Sources import Text.Parsec.Pos (newPos) import Text.Pandoc.Options import Text.Pandoc.Definition -import Text.Pandoc.Shared (addPandocAttributes, tshow) +import Text.Pandoc.Shared (addPandocAttributes, tshow, compactifyTable) import qualified Text.Pandoc.UTF8 as UTF8 import Djot (ParseOptions(..), SourcePosOption(..), parseDoc, Pos(..)) import qualified Djot.AST as D @@ -151,7 +151,8 @@ convertBlock (D.Node pos attr bl) = addAttrToBlock pos attr <$> mapM toRow hs <*> mapM toRow rs tbodies <- mapM toTableBody bodies let tfoot = TableFoot mempty [] - pure $ singleton $ Table mempty capt colspecs thead tbodies tfoot + pure $ singleton $ compactifyTable + $ Table mempty capt colspecs thead tbodies tfoot D.RawBlock (D.Format fmt) bs -> pure $ rawBlock (UTF8.toText fmt) (UTF8.toText bs) diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index bfb52b76b..c39fe2c59 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -80,7 +80,6 @@ import Data.Char (isSpace) import qualified Data.Map as M import qualified Data.Text as T import Data.Maybe (isJust, fromMaybe, mapMaybe) -import Data.Sequence (ViewL (..), viewl) import qualified Data.Sequence as Seq import qualified Data.Set as Set import Citeproc (ItemId(..), Val(TextVal,FancyVal), Reference(..), CitationItem(..)) @@ -605,18 +604,10 @@ makeHeaderAnchor' (Header n (ident, classes, kvs) ils) = return $ Header n (newIdent, classes, kvs) ils makeHeaderAnchor' blk = return blk --- Rewrite a standalone paragraph block as a plain -singleParaToPlain :: Blocks -> Blocks -singleParaToPlain blks - | (Para ils :< seeq) <- viewl $ unMany blks - , Seq.null seeq = - singleton $ Plain ils -singleParaToPlain blks = blks - cellToCell :: PandocMonad m => RowSpan -> Docx.Cell -> DocxContext m Pandoc.Cell cellToCell rowSpan (Docx.Cell align gridSpan _ bps) = do blks <- smushBlocks <$> mapM bodyPartToBlocks bps - let blks' = singleParaToPlain $ fromList $ blocksToDefinitions $ blocksToBullets $ toList blks + let blks' = fromList $ blocksToDefinitions $ blocksToBullets $ toList blks return (cell (convertAlign align) rowSpan (ColSpan (fromIntegral gridSpan)) blks') @@ -860,7 +851,8 @@ bodyPartToBlocks (Tbl mbsty cap grid look parts) = do let attr = case mbsty of Just sty | extStylesEnabled -> ("", [], [("custom-style", sty)]) _ -> nullAttr - return $ tableWith attr cap' + return $ compactifyTable + $ tableWith attr cap' (zip alignments widths) (TableHead nullAttr headerCells) [TableBody nullAttr 0 [] bodyCells] diff --git a/src/Text/Pandoc/Readers/DokuWiki.hs b/src/Text/Pandoc/Readers/DokuWiki.hs index c40f065d0..1d4eabfcf 100644 --- a/src/Text/Pandoc/Readers/DokuWiki.hs +++ b/src/Text/Pandoc/Readers/DokuWiki.hs @@ -28,7 +28,7 @@ import Text.Pandoc.Class.PandocMonad (PandocMonad (..)) import Text.Pandoc.Definition import Text.Pandoc.Options import Text.Pandoc.Parsing hiding (enclosed) -import Text.Pandoc.Shared (trim, stringifyInlines, tshow) +import Text.Pandoc.Shared (trim, stringifyInlines, tshow, compactifyTable) import Data.List (isPrefixOf, isSuffixOf, groupBy) import qualified Safe @@ -517,7 +517,8 @@ table = do let attrs = map (\(a, _) -> (a, ColWidthDefault)) firstRow let toRow = Row nullAttr . map B.simpleCell toHeaderRow l = [toRow l | not (null l)] - pure $ B.table B.emptyCaption + pure $ compactifyTable + $ B.table B.emptyCaption attrs (TableHead nullAttr $ toHeaderRow (map snd headerRow)) [TableBody nullAttr 0 [] $ map (toRow . (map snd)) body] diff --git a/src/Text/Pandoc/Readers/LaTeX/Table.hs b/src/Text/Pandoc/Readers/LaTeX/Table.hs index a0a127798..23fcd0a97 100644 --- a/src/Text/Pandoc/Readers/LaTeX/Table.hs +++ b/src/Text/Pandoc/Readers/LaTeX/Table.hs @@ -15,7 +15,7 @@ import Data.Maybe (fromMaybe) import qualified Data.Text as T import Control.Applicative ((<|>), optional, many) import Control.Monad (when, void) -import Text.Pandoc.Shared (safeRead, trim) +import Text.Pandoc.Shared (safeRead, trim, compactifyTable) import Text.Pandoc.Logging (LogMessage(SkippedContent)) import Text.Pandoc.Walk (walkM) import Text.Pandoc.Parsing hiding (blankline, many, mathDisplay, mathInline, @@ -190,7 +190,7 @@ parseTableCell block = do -- The parsing of empty cells is important in LaTeX, especially when dealing -- with multirow/multicolumn. See #6603. parseEmptyCell = spaces $> emptyCell - parseSimpleCell = simpleCell <$> (plainify . mconcat <$> many block) + parseSimpleCell = simpleCell . mconcat <$> many block cellAlignment :: PandocMonad m => LP m Alignment @@ -205,11 +205,6 @@ cellAlignment = skipMany (symbol '|') *> alignment <* skipMany (symbol '|') "*" -> AlignDefault _ -> AlignDefault -plainify :: Blocks -> Blocks -plainify bs = case toList bs of - [Para ils] -> plain (fromList ils) - _ -> bs - multirowCell :: PandocMonad m => LP m Blocks -> LP m Cell multirowCell block = controlSeq "multirow" >> do -- Full prototype for \multirow macro is: @@ -221,7 +216,7 @@ multirowCell block = controlSeq "multirow" >> do _ <- optional $ symbol '[' *> manyTill anyTok (symbol ']') -- bigstrut-related _ <- symbol '{' *> manyTill anyTok (symbol '}') -- Cell width _ <- optional $ symbol '[' *> manyTill anyTok (symbol ']') -- Length used for fine-tuning - content <- symbol '{' *> (plainify . mconcat <$> many block) <* symbol '}' + content <- symbol '{' *> (mconcat <$> many block) <* symbol '}' return $ cell AlignDefault (RowSpan nrows) (ColSpan 1) content multicolumnCell :: PandocMonad m => LP m Blocks -> LP m Cell @@ -230,7 +225,7 @@ multicolumnCell block = controlSeq "multicolumn" >> do alignment <- symbol '{' *> cellAlignment <* symbol '}' let singleCell = do - content <- plainify . mconcat <$> many block + content <- mconcat <$> many block return $ cell alignment (RowSpan 1) (ColSpan span') content -- Two possible contents: either a \multirow cell, or content. @@ -357,7 +352,8 @@ simpTable block inline envname hasWidthParameter = try $ do let th = fixTableHead $ TableHead nullAttr header' let tbs = [fixTableBody $ TableBody nullAttr 0 [] rows] let tf = TableFoot nullAttr [] - return $ table emptyCaption (zip aligns widths) th tbs tf + return $ compactifyTable + $ table emptyCaption (zip aligns widths) th tbs tf addTableCaption :: PandocMonad m => Blocks -> LP m Blocks addTableCaption = walkM go diff --git a/src/Text/Pandoc/Readers/Man.hs b/src/Text/Pandoc/Readers/Man.hs index 0b5d58d69..1d030aafc 100644 --- a/src/Text/Pandoc/Readers/Man.hs +++ b/src/Text/Pandoc/Readers/Man.hs @@ -33,7 +33,7 @@ import Text.Pandoc.Readers.Roff -- TODO explicit imports import qualified Text.Pandoc.Parsing as P import qualified Data.Foldable as Foldable import qualified Data.Set as Set -import Text.Pandoc.Shared (extractSpaces) +import Text.Pandoc.Shared (extractSpaces, compactifyTable) data ManState = ManState { readerOptions :: ReaderOptions , manLogMessages :: []LogMessage @@ -129,7 +129,8 @@ parseTable = do let widths = if isPlainTable then repeat ColWidthDefault else repeat $ ColWidth (1.0 / fromIntegral (length alignments)) - return $ B.table B.emptyCaption (zip alignments widths) + return $ compactifyTable + $ B.table B.emptyCaption (zip alignments widths) (TableHead nullAttr $ toHeaderRow headerRow) [TableBody nullAttr 0 [] $ map toRow bodyRows] (TableFoot nullAttr [])) <|> fallback pos diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 5c754a567..f6b0d419c 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -1534,7 +1534,7 @@ table = try $ do return $ do caption' <- caption (TableComponents _attr _capt colspecs th tb tf) <- tableComponents - return $ B.tableWith attr + return $ compactifyTable $ B.tableWith attr (B.simpleCaption $ B.plain caption') colspecs th tb tf -- diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs index 50189194c..4b048bf58 100644 --- a/src/Text/Pandoc/Readers/MediaWiki.hs +++ b/src/Text/Pandoc/Readers/MediaWiki.hs @@ -38,7 +38,7 @@ import Text.Pandoc.Options import Text.Pandoc.Parsing hiding (tableCaption) import Text.Pandoc.Readers.HTML (htmlTag, isCommentTag, toAttr) import Text.Pandoc.Shared (formatCode, safeRead, splitTextBy, stringifyInlines, - stripTrailingNewlines, trim, tshow) + stripTrailingNewlines, trim, tshow, compactifyTable) import Text.Pandoc.XML (fromEntities) -- | Read mediawiki from an input string and return a Pandoc document. @@ -299,7 +299,8 @@ table = do else ([], hdr:rows') let toRow = Row nullAttr toHeaderRow l = [toRow l | not (null l)] - return $ B.table (B.simpleCaption $ B.plain caption) + return $ compactifyTable + $ B.table (B.simpleCaption $ B.plain caption) cellspecs (TableHead nullAttr $ toHeaderRow headers) [TableBody nullAttr 0 [] $ map toRow rows] diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs index 88504481a..a0e97653a 100644 --- a/src/Text/Pandoc/Readers/Muse.hs +++ b/src/Text/Pandoc/Readers/Muse.hs @@ -36,7 +36,7 @@ import Text.Pandoc.Definition import Text.Pandoc.Logging import Text.Pandoc.Options import Text.Pandoc.Parsing -import Text.Pandoc.Shared (trimr, tshow) +import Text.Pandoc.Shared (trimr, tshow, compactifyTable) -- | Read Muse from an input string and return a Pandoc document. readMuse :: (PandocMonad m, ToSources a) @@ -645,6 +645,7 @@ data MuseTableElement = MuseHeaderRow [Blocks] museToPandocTable :: MuseTable -> Blocks museToPandocTable (MuseTable caption headers body footers) = + compactifyTable $ B.table (B.simpleCaption $ B.plain caption) attrs (TableHead nullAttr $ toHeaderRow headRow) diff --git a/src/Text/Pandoc/Readers/ODT/ContentReader.hs b/src/Text/Pandoc/Readers/ODT/ContentReader.hs index 017402357..56e1e009f 100644 --- a/src/Text/Pandoc/Readers/ODT/ContentReader.hs +++ b/src/Text/Pandoc/Readers/ODT/ContentReader.hs @@ -731,8 +731,8 @@ read_table = matchingElement NsTable "table" -- | A table without a caption. table' :: ([[Cell]], [[Cell]]) -> Blocks -table' (headers, rows) = - table emptyCaption (replicate numcols defaults) th [tb] tf +table' (headers, rows) = compactifyTable $ + table emptyCaption (replicate numcols defaults) th [tb] tf where defaults = (AlignDefault, ColWidthDefault) numcols = maximum $ map length $ headers ++ rows diff --git a/src/Text/Pandoc/Readers/Org/Blocks.hs b/src/Text/Pandoc/Readers/Org/Blocks.hs index cddd56382..1b3619eec 100644 --- a/src/Text/Pandoc/Readers/Org/Blocks.hs +++ b/src/Text/Pandoc/Readers/Org/Blocks.hs @@ -31,7 +31,7 @@ import Text.Pandoc.Builder (Blocks, Inlines, Many(..)) import Text.Pandoc.Class.PandocMonad (PandocMonad) import Text.Pandoc.Definition import Text.Pandoc.Options -import Text.Pandoc.Shared (compactify, compactifyDL, safeRead) +import Text.Pandoc.Shared (compactify, compactifyDL, safeRead, compactifyTable) import Control.Monad (foldM, guard, mzero, void) import Data.Bifunctor (bimap) @@ -701,8 +701,8 @@ table = try $ do pure $ B.simpleCaption . B.plain $ ils' let attr = (fromMaybe mempty identMb, [], blockAttrKeyValues blockAttrs) - pure $ B.tableWith attr capt cs th tb tf - _ -> tbl -- should not happen + pure $ compactifyTable $ B.tableWith attr capt cs th tb tf + _ -> compactifyTable <$> tbl -- should not happen else mempty -- | A normal org table @@ -718,7 +718,8 @@ orgToPandocTable (OrgTable colProps heads lns) = let totalWidth = if any (isJust . columnRelWidth) colProps then Just . sum $ map (fromMaybe 1 . columnRelWidth) colProps else Nothing - in B.tableWith nullAttr (Caption Nothing mempty) + in compactifyTable $ + B.tableWith nullAttr (Caption Nothing mempty) (map (convertColProp totalWidth) colProps) (TableHead nullAttr $ toHeaderRow heads) [TableBody nullAttr 0 [] $ map toRow lns] diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index ff8efba18..ae665613a 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -1046,22 +1046,15 @@ csvTableDirective top fields rawcsv = do _ -> replicate numOfCols ColWidthDefault let toRow = Row nullAttr . map B.simpleCell toHeaderRow l = [toRow l | not (null l)] - return $ B.table (B.simpleCaption $ B.plain title) + return $ compactifyTable + $ B.table (B.simpleCaption $ B.plain title) (zip (replicate numOfCols AlignDefault) widths) (TableHead nullAttr $ toHeaderRow headerRow) [TableBody nullAttr 0 [] $ map toRow bodyRows] (TableFoot nullAttr []) -singleParaToPlain :: Blocks -> Blocks -singleParaToPlain bs = - case B.toList bs of - [Para ils] -> B.fromList [Plain ils] - _ -> bs - parseCell :: PandocMonad m => Text -> RSTParser m Blocks -parseCell t = singleParaToPlain - <$> parseFromString' parseBlocks (trim t <> "\n\n") - +parseCell t = parseFromString' parseBlocks (trim t <> "\n\n") -- TODO: -- - Only supports :format: fields with a single format for :raw: roles, @@ -1516,7 +1509,8 @@ gridTable = runIdentity <$> gridTableWith (Identity <$> parseBlocks) table :: PandocMonad m => RSTParser m Blocks -table = gridTable <|> simpleTable False <|> simpleTable True "table" +table = compactifyTable <$> + (gridTable <|> simpleTable False <|> simpleTable True "table") -- -- inline diff --git a/src/Text/Pandoc/Readers/TWiki.hs b/src/Text/Pandoc/Readers/TWiki.hs index ac7254c9e..32289f3e2 100644 --- a/src/Text/Pandoc/Readers/TWiki.hs +++ b/src/Text/Pandoc/Readers/TWiki.hs @@ -28,7 +28,7 @@ import Text.Pandoc.Definition import Text.Pandoc.Options import Text.Pandoc.Parsing hiding (enclosed) import Text.Pandoc.Readers.HTML (htmlTag, isCommentTag) -import Text.Pandoc.Shared (tshow) +import Text.Pandoc.Shared (tshow, compactifyTable) import Text.Pandoc.XML (fromEntities) -- | Read twiki from an input string and return a Pandoc document. @@ -217,7 +217,8 @@ table = try $ do return $ buildTable mempty rows $ fromMaybe (align rows, columns rows) thead where buildTable caption rows (aligns, heads) - = B.table (B.simpleCaption $ B.plain caption) + = compactifyTable $ B.table + (B.simpleCaption $ B.plain caption) aligns (TableHead nullAttr $ toHeaderRow heads) [TableBody nullAttr 0 [] $ map toRow rows] diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs index 5690ed256..bf504bb1a 100644 --- a/src/Text/Pandoc/Readers/Textile.hs +++ b/src/Text/Pandoc/Readers/Textile.hs @@ -56,7 +56,7 @@ import Text.Pandoc.Options import Text.Pandoc.Parsing import Text.Pandoc.Readers.HTML (htmlTag, isBlockTag, isInlineTag) import Text.Pandoc.Readers.LaTeX (rawLaTeXBlock, rawLaTeXInline) -import Text.Pandoc.Shared (trim, tshow) +import Text.Pandoc.Shared (trim, tshow, compactifyTable) import Text.Read (readMaybe) -- | Parse a Textile text and return a Pandoc document. @@ -452,7 +452,8 @@ table = try $ do transpose $ map (map (snd . fst)) (headers:rows) let toRow = Row nullAttr . map B.simpleCell toHeaderRow l = [toRow l | not (null l)] - return $ B.table (B.simpleCaption $ B.plain caption) + return $ compactifyTable + $ 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] diff --git a/src/Text/Pandoc/Readers/Txt2Tags.hs b/src/Text/Pandoc/Readers/Txt2Tags.hs index 6e3994342..77df32914 100644 --- a/src/Text/Pandoc/Readers/Txt2Tags.hs +++ b/src/Text/Pandoc/Readers/Txt2Tags.hs @@ -33,7 +33,7 @@ import Data.Time (defaultTimeLocale) import Text.Pandoc.Definition import Text.Pandoc.Options import Text.Pandoc.Parsing hiding (space, spaces, uri) -import Text.Pandoc.Shared (compactify, compactifyDL) +import Text.Pandoc.Shared (compactify, compactifyDL, compactifyTable) import Text.Pandoc.URI (escapeURI) type T2T = ParsecT Sources ParserState (Reader T2TMeta) @@ -274,7 +274,8 @@ table = try $ do let headerPadded = if null tableHeader then mempty else pad size tableHeader let toRow = Row nullAttr . map B.simpleCell toHeaderRow l = [toRow l | not (null l)] - return $ B.table B.emptyCaption + return $ compactifyTable + $ B.table B.emptyCaption (zip aligns (replicate ncolumns ColWidthDefault)) (TableHead nullAttr $ toHeaderRow headerPadded) [TableBody nullAttr 0 [] $ map toRow rowsPadded] diff --git a/src/Text/Pandoc/Readers/Typst.hs b/src/Text/Pandoc/Readers/Typst.hs index 1cd394c35..ebe8efb02 100644 --- a/src/Text/Pandoc/Readers/Typst.hs +++ b/src/Text/Pandoc/Readers/Typst.hs @@ -1,6 +1,7 @@ {-# LANGUAGE RankNTypes #-} {-# LANGUAGE BangPatterns #-} {-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE LambdaCase #-} @@ -30,7 +31,7 @@ import Text.Pandoc.Definition import Typst ( parseTypst, evaluateTypst ) import Text.Pandoc.Error (PandocError(..)) import Text.Pandoc.Translations (Term(References), translateTerm) -import Text.Pandoc.Shared (tshow, blocksToInlines) +import Text.Pandoc.Shared (tshow, blocksToInlines, compactifyTable) import Text.Pandoc.Parsing (registerHeader, reportLogMessages) import Control.Monad.Except (throwError) import Control.Monad (MonadPlus (mplus), void, guard, foldM) @@ -763,14 +764,13 @@ parseTable mbident fields = do let headRows = getRows THeader tableData let bodyRows = getRows TBody tableData let footRows = getRows TFooter tableData - pure $ - B.tableWith - (fromMaybe "" mbident, [], []) - (B.Caption mempty mempty) - colspecs - (B.TableHead B.nullAttr headRows) - [B.TableBody B.nullAttr 0 [] bodyRows] - (B.TableFoot B.nullAttr footRows) + pure $ compactifyTable $ B.tableWith + (fromMaybe "" mbident, [], []) + (B.Caption mempty mempty) + colspecs + (B.TableHead B.nullAttr headRows) + [B.TableBody B.nullAttr 0 [] bodyRows] + (B.TableFoot B.nullAttr footRows) data TableSection = THeader | TBody | TFooter deriving (Show, Ord, Eq) diff --git a/test/asciidoc-reader.native b/test/asciidoc-reader.native index a55002d34..5a8cf7737 100644 --- a/test/asciidoc-reader.native +++ b/test/asciidoc-reader.native @@ -1837,7 +1837,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "This" , Space , Str "content" @@ -1866,7 +1866,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "This" , Space , Str "line" @@ -1911,7 +1911,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "When" , Space , Str "the" @@ -1988,7 +1988,7 @@ Pandoc AlignRight (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Strong [ Str "This" , Space @@ -2021,7 +2021,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "The" , Space , Str "cell" @@ -2085,7 +2085,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Column" , Space , Str "1," @@ -2100,7 +2100,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Column" , Space , Str "2," @@ -2123,7 +2123,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2142,7 +2142,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2164,7 +2164,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2183,7 +2183,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2224,7 +2224,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Column" , Space , Str "1," @@ -2239,7 +2239,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Column" , Space , Str "2," @@ -2262,7 +2262,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2281,7 +2281,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2303,7 +2303,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2322,7 +2322,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2393,7 +2393,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2412,7 +2412,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2434,7 +2434,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2453,7 +2453,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2498,13 +2498,13 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Cell" , Space , Str "A1" ] ] + [ Plain [ Str "Cell" , Space , Str "A1" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Cell" , Space , Str "B1" ] ] + [ Plain [ Str "Cell" , Space , Str "B1" ] ] ] , Row ( "" , [] , [] ) @@ -2513,13 +2513,13 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Cell" , Space , Str "A2" ] ] + [ Plain [ Str "Cell" , Space , Str "A2" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Cell" , Space , Str "B2" ] ] + [ Plain [ Str "Cell" , Space , Str "B2" ] ] ] , Row ( "" , [] , [] ) @@ -2528,13 +2528,13 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Cell" , Space , Str "A3" ] ] + [ Plain [ Str "Cell" , Space , Str "A3" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Cell" , Space , Str "B3" ] ] + [ Plain [ Str "Cell" , Space , Str "B3" ] ] ] ] ] @@ -2559,7 +2559,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Column" , Space , Str "1," @@ -2574,7 +2574,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Column" , Space , Str "2," @@ -2589,7 +2589,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Column" , Space , Str "3," @@ -2607,7 +2607,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2626,7 +2626,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2645,7 +2645,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2667,7 +2667,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Column" , Space , Str "1," @@ -2682,7 +2682,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Column" , Space , Str "2," @@ -2697,7 +2697,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Column" , Space , Str "3," @@ -2730,7 +2730,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Column" , Space , Str "1," @@ -2745,7 +2745,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Column" , Space , Str "2," @@ -2763,7 +2763,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2782,7 +2782,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2804,7 +2804,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2823,7 +2823,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -2849,7 +2849,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Column" , Space , Str "1," @@ -2864,7 +2864,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Column" , Space , Str "2," @@ -2895,13 +2895,13 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Column" , Space , Str "Name" ] ] + [ Plain [ Str "Column" , Space , Str "Name" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Column" , Space , Str "Name" ] ] + [ Plain [ Str "Column" , Space , Str "Name" ] ] ] , Row ( "" , [] , [] ) @@ -2910,7 +2910,7 @@ Pandoc AlignCenter (RowSpan 1) (ColSpan 2) - [ Para + [ Plain [ Str "This" , Space , Str "cell" @@ -2958,7 +2958,7 @@ Pandoc AlignCenter (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "This" , Space , Str "content" @@ -3007,7 +3007,7 @@ Pandoc AlignCenter (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "This" , Space , Str "content" @@ -3345,13 +3345,13 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Code ( "" , [] , [] ) "monospace" ] ] + [ Plain [ Code ( "" , [] , [] ) "monospace" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Code ( "" , [] , [] ) "mono" ] ] + [ Plain [ Code ( "" , [] , [] ) "mono" ] ] ] , Row ( "" , [] , [] ) @@ -3360,13 +3360,13 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "default" ] ] + [ Plain [ Str "default" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Code ( "" , [] , [] ) "mono" ] ] + [ Plain [ Code ( "" , [] , [] ) "mono" ] ] ] ] ] @@ -3697,7 +3697,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Column" , Space , Str "1," @@ -3712,7 +3712,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Column" , Space , Str "2," @@ -3727,7 +3727,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Column" , Space , Str "3," @@ -3745,7 +3745,7 @@ Pandoc AlignDefault (RowSpan 2) (ColSpan 2) - [ Para + [ Plain [ Str "This" , Space , Str "cell" @@ -3768,7 +3768,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -3790,7 +3790,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -3812,7 +3812,7 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 3) - [ Para + [ Plain [ Str "Cell" , Space , Str "in" @@ -3850,19 +3850,19 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Artist" ] ] + [ Plain [ Str "Artist" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Track" ] ] + [ Plain [ Str "Track" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Genre" ] ] + [ Plain [ Str "Genre" ] ] ] ]) [ TableBody @@ -3876,19 +3876,19 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Baauer" ] ] + [ Plain [ Str "Baauer" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Harlem" , Space , Str "Shake" ] ] + [ Plain [ Str "Harlem" , Space , Str "Shake" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Hip" , Space , Str "Hop" ] ] + [ Plain [ Str "Hip" , Space , Str "Hop" ] ] ] , Row ( "" , [] , [] ) @@ -3897,19 +3897,19 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "The" , Space , Str "Lumineers" ] ] + [ Plain [ Str "The" , Space , Str "Lumineers" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Ho" , Space , Str "Hey" ] ] + [ Plain [ Str "Ho" , Space , Str "Hey" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Folk" , Space , Str "Rock" ] ] + [ Plain [ Str "Folk" , Space , Str "Rock" ] ] ] ] ] @@ -3934,19 +3934,19 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Artist" ] ] + [ Plain [ Str "Artist" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Track" ] ] + [ Plain [ Str "Track" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Genre" ] ] + [ Plain [ Str "Genre" ] ] ] , Row ( "" , [] , [] ) @@ -3955,19 +3955,19 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Baauer" ] ] + [ Plain [ Str "Baauer" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Harlem" , Space , Str "Shake" ] ] + [ Plain [ Str "Harlem" , Space , Str "Shake" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Hip" , Space , Str "Hop" ] ] + [ Plain [ Str "Hip" , Space , Str "Hop" ] ] ] ] ] @@ -3995,19 +3995,19 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "a" ] ] + [ Plain [ Str "a" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "b" ] ] + [ Plain [ Str "b" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "c" ] ] + [ Plain [ Str "c" ] ] ] , Row ( "" , [] , [] ) @@ -4016,19 +4016,19 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "d" ] ] + [ Plain [ Str "d" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "e" ] ] + [ Plain [ Str "e" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "f" ] ] + [ Plain [ Str "f" ] ] ] ] ] @@ -4053,19 +4053,19 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Artist" ] ] + [ Plain [ Str "Artist" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Track" ] ] + [ Plain [ Str "Track" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Genre" ] ] + [ Plain [ Str "Genre" ] ] ] , Row ( "" , [] , [] ) @@ -4074,19 +4074,19 @@ Pandoc AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Robyn" ] ] + [ Plain [ Str "Robyn" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Indestructible" ] ] + [ Plain [ Str "Indestructible" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) - [ Para [ Str "Dance" ] ] + [ Plain [ Str "Dance" ] ] ] ] ] diff --git a/test/command/10390.md b/test/command/10390.md index 78d12e874..8ae643eef 100644 --- a/test/command/10390.md +++ b/test/command/10390.md @@ -11,12 +11,12 @@ Overview of basic table markup -

Key

+Key -

Value

+Value diff --git a/test/command/10490.md b/test/command/10490.md index 05143ef95..1ca283aaf 100644 --- a/test/command/10490.md +++ b/test/command/10490.md @@ -18,31 +18,31 @@ - - + + - - - - + + + + - - - - - + + + + + - - - - - + + + + +

Witness program version

Hash size

Witness program versionHash size

Mainnet

Testnet

Mainnet

Testnet

MainnetTestnetMainnetTestnet

0

p2

QW

7Xh

T7n

0p2QW7XhT7n

1

p4

QY

7Xq

T7w

1p4QY7XqT7w
diff --git a/test/command/1166.md b/test/command/1166.md index b63682537..3efd9403e 100644 --- a/test/command/1166.md +++ b/test/command/1166.md @@ -24,15 +24,15 @@ col 1 col 2 -1 -Second column of row 1. +

1

+

Second column of row 1.

-2 -Second column of row 2. Second line of paragraph. +

2

+

Second column of row 2. Second line of paragraph.

-3 +

3