diff options
| author | John MacFarlane <[email protected]> | 2024-09-03 14:26:53 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2024-09-03 14:26:53 -0700 |
| commit | 6be41d1c62da2c6c941a7de47a7e4c0132b6bfa6 (patch) | |
| tree | 38b089480853ca08fdbdeee344a94db11be49e1b | |
| parent | 9953f1d2563589f8d88b8d27d71132315c2f9770 (diff) | |
ANSI writer: Remove Figure and Table labels and numbers.
| -rw-r--r-- | src/Text/Pandoc/Writers/ANSI.hs | 33 | ||||
| -rw-r--r-- | test/ansi-test.ansi | 7 |
2 files changed, 12 insertions, 28 deletions
diff --git a/src/Text/Pandoc/Writers/ANSI.hs b/src/Text/Pandoc/Writers/ANSI.hs index d54319703..202813efa 100644 --- a/src/Text/Pandoc/Writers/ANSI.hs +++ b/src/Text/Pandoc/Writers/ANSI.hs @@ -25,7 +25,6 @@ import Text.Pandoc.Logging import Text.Pandoc.Options import Text.Pandoc.Shared import Text.Pandoc.Templates (renderTemplate) -import qualified Text.Pandoc.Translations as L import Text.Pandoc.Writers.Math(texMathToInlines) import Text.Pandoc.Writers.Shared import qualified Data.Text as T @@ -44,7 +43,6 @@ data WriterState = WriterState { , stInner :: Bool -- Are we at the document's top-level or in a nested construct? , stNextFigureNum :: Int , stInFigure :: Bool - , stNextTableNum :: Int , stInTable :: Bool } @@ -68,7 +66,6 @@ writeANSI opts document = stInner = False, stNextFigureNum = 1, stInFigure = False, - stNextTableNum = 1, stInTable = False } @@ -178,15 +175,10 @@ blockToANSI opts (BlockQuote blocks) = do -- TODO: Row spans don't work blockToANSI opts (Table _ (Caption _ caption) colSpecs (TableHead _ thead) tbody (TableFoot _ tfoot)) = do let captionInlines = blocksToInlines caption - tableTerm <- L.translateTerm L.Table - num <- gets stNextTableNum - modify $ \s -> s{stNextTableNum = num + 1} - let label = D.literal tableTerm <+> D.literal (tshow num) - captionMarkup <- if null captionInlines - then return (D.italic label) - else do - cap <- inlineListToANSI opts (blocksToInlines caption) - return $ (D.italic (label <> D.literal ":")) <+> cap + captionMarkup <- + if null captionInlines + then return mempty + else D.nest 2 <$> inlineListToANSI opts (blocksToInlines caption) wasTable <- gets stInTable modify $ \s -> s{stInTable = True} let tw = writerColumns opts @@ -206,7 +198,7 @@ blockToANSI opts (Table _ (Caption _ caption) colSpecs (TableHead _ thead) tbody body' <- mapM (goRow widths . unRow) (unBodies tbody) foot' <- mapM (goRow widths . unRow) tfoot modify $ \s -> s{stInTable = wasTable} - return $ D.vcat (head' <> decor <> body' <> decor <> foot') $$ captionMarkup + return $ D.vcat (head' <> decor <> body' <> decor <> foot') $+$ captionMarkup where unRow (Row _ cs) = cs unBody (TableBody _ _ hd bd) = hd <> bd @@ -253,20 +245,15 @@ blockToANSI opts (DefinitionList items) = do blockToANSI opts (Figure _ (Caption _ caption) body) = do let captionInlines = blocksToInlines caption - figTerm <- L.translateTerm L.Figure - num <- gets stNextFigureNum figState <- gets stInFigure - modify $ \s -> s{stNextFigureNum = num + 1} - let label = D.literal figTerm <+> D.literal (tshow num) - captionMarkup <- if null captionInlines - then return (D.italic label) - else do - cap <- inlineListToANSI opts (blocksToInlines caption) - return $ (D.italic (label <> D.literal ":")) <+> cap + captionMarkup <- + if null captionInlines + then return mempty + else D.nest 2 <$> inlineListToANSI opts (blocksToInlines caption) modify $ \s -> s{stInFigure = True} contents <- blockListToANSI opts body modify $ \s -> s{stInFigure = figState} - return $ contents $$ captionMarkup + return $ contents $+$ captionMarkup -- Auxiliary functions for lists: diff --git a/test/ansi-test.ansi b/test/ansi-test.ansi index baf92f158..ce1ec6159 100644 --- a/test/ansi-test.ansi +++ b/test/ansi-test.ansi @@ -45,7 +45,8 @@ Second row 5.0 Here’s another one. Note the blank line between rows. ─────────── ────────── ──────────── ────────────────────────── -[22m[3m[39m[49m[24m[29mTable 1:[0m Here’s the caption. It may span multiple lines. + + Here’s the caption. It may span multiple lines. Multiline table without caption: @@ -58,7 +59,6 @@ Second row 5.0 Here’s another one. Note the blank line between rows. ─────────── ────────── ──────────── ────────────────────────── -[22m[3m[39m[49m[24m[29mTable 2[0m Table without column headers: @@ -67,7 +67,6 @@ Table without column headers: 123 123 123 123 1 1 1 1 ───────────────── ───────────────── ───────────────── ───────────────── -[22m[3m[39m[49m[24m[29mTable 3[0m Footnote¹ @@ -83,14 +82,12 @@ r1 bis • b 2 • b 2 ────────────────── ─────────── ──────────── -[22m[3m[39m[49m[24m[29mTable 4[0m East Asian characters have double width ── ──── 魚 fish ── ──── -[22m[3m[39m[49m[24m[29mTable 5[0m [22m[23m[31m[49m[24m[29mcode block[0m [22m[23m[31m[49m[24m[29m >>> ## ``[0m |
