From 4340bd52c49b987087e123de2eae4464b300332f Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 15 Aug 2021 15:05:54 -0700 Subject: Make docx writer sensitive to `native_numbering` extension. Figure and table numbers are now only included if `native_numbering` is enabled. (By default it is disabled.) This is a behavior change with respect to 2.14.1, but the behavior is that of previous versions. The change was necessary to avoid incompatibilities between pandoc's native numbering and third-party cross reference filters like pandoc-crossref. Closes #7499. --- src/Text/Pandoc/Writers/Docx/Table.hs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/Text/Pandoc/Writers/Docx') diff --git a/src/Text/Pandoc/Writers/Docx/Table.hs b/src/Text/Pandoc/Writers/Docx/Table.hs index 7a84c5278..e23856f28 100644 --- a/src/Text/Pandoc/Writers/Docx/Table.hs +++ b/src/Text/Pandoc/Writers/Docx/Table.hs @@ -20,6 +20,8 @@ import Text.Pandoc.Definition import Text.Pandoc.Class.PandocMonad (PandocMonad, translateTerm) import Text.Pandoc.Writers.Docx.Types import Text.Pandoc.Shared +import Text.Pandoc.Options (WriterOptions, isEnabled) +import Text.Pandoc.Extensions (Extension(Ext_native_numbering)) import Text.Printf (printf) import Text.Pandoc.Writers.GridTable hiding (Table) import Text.Pandoc.Writers.OOXML @@ -29,10 +31,11 @@ import qualified Text.Pandoc.Translations as Term import qualified Text.Pandoc.Writers.GridTable as Grid tableToOpenXML :: PandocMonad m - => ([Block] -> WS m [Content]) + => WriterOptions + -> ([Block] -> WS m [Content]) -> Grid.Table -> WS m [Content] -tableToOpenXML blocksToOpenXML gridTable = do +tableToOpenXML opts blocksToOpenXML gridTable = do setFirstPara let (Grid.Table (ident,_,_) caption colspecs _rowheads thead tbodies tfoot) = gridTable @@ -50,7 +53,9 @@ tableToOpenXML blocksToOpenXML gridTable = do then return [] else withParaPropM (pStyleM "Table Caption") $ blocksToOpenXML - $ addLabel tableid tablename tablenum captionBlocks + $ if isEnabled Ext_native_numbering opts + then addLabel tableid tablename tablenum captionBlocks + else captionBlocks -- We set "in table" after processing the caption, because we don't -- want the "Table Caption" style to be overwritten with "Compact". modify $ \s -> s { stInTable = True } -- cgit v1.2.3 From 6509ff62043b6445098cc9c94628fab464638f62 Mon Sep 17 00:00:00 2001 From: Tristan Stenner Date: Tue, 26 Oct 2021 15:03:12 +0200 Subject: Docx writer: move ": " out of the caption bookmark. This is needed so that native references to the figure are included as "As seen in Figure X, it is..." instead of "As seen in [Figure: , it is..." --- src/Text/Pandoc/Writers/Docx.hs | 3 +-- src/Text/Pandoc/Writers/Docx/Table.hs | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src/Text/Pandoc/Writers/Docx') diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index fccbb0719..ce7133f33 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -880,8 +880,7 @@ blockToOpenXML' opts (SimpleFigure attr@(imgident, _, _) alt (src, tit)) = do (" " \\* ARABIC \">" <> tshow fignum - <> ""), - Str ":", Space] : alt + <> "")] : Str ": " : alt else alt return $ Elem (mknode "w:p" [] (map Elem paraProps ++ contents)) diff --git a/src/Text/Pandoc/Writers/Docx/Table.hs b/src/Text/Pandoc/Writers/Docx/Table.hs index e23856f28..4dc4ad6a2 100644 --- a/src/Text/Pandoc/Writers/Docx/Table.hs +++ b/src/Text/Pandoc/Writers/Docx/Table.hs @@ -98,8 +98,8 @@ tableToOpenXML opts blocksToOpenXML gridTable = do addLabel :: Text -> Text -> Int -> [Block] -> [Block] addLabel tableid tablename tablenum bs = case bs of - (Para ils : rest) -> Para (label : Space : ils) : rest - (Plain ils : rest) -> Plain (label : Space : ils) : rest + (Para ils : rest) -> Para (label : Str ": " : ils) : rest + (Plain ils : rest) -> Plain (label : Str ": " : ils) : rest _ -> Para [label] : bs where label = Span (tableid,[],[]) @@ -108,8 +108,7 @@ addLabel tableid tablename tablenum bs = (" " \\* ARABIC \">" <> tshow tablenum - <> ""), - Str ":"] + <> "")] -- | Parts of a table data RowType = HeadRow | BodyRow | FootRow -- cgit v1.2.3