From 8028de33220af0a43ac8d14021b7fa2b98b22d64 Mon Sep 17 00:00:00 2001 From: Nils Carlson Date: Sat, 21 Sep 2019 20:12:00 +0000 Subject: odt: Add external option for native numbering This adds an external options +native_numbering to the ODT writer enabling enumeration of figures and tables in ODT output. --- MANUAL.txt | 10 ++++++ src/Text/Pandoc/Extensions.hs | 1 + src/Text/Pandoc/Writers/OpenDocument.hs | 14 ++++---- test/command/5474-figures.md | 15 ++++++++ test/command/5474-tables.md | 63 +++++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 test/command/5474-figures.md create mode 100644 test/command/5474-tables.md diff --git a/MANUAL.txt b/MANUAL.txt index c9ff7bea5..9ce2d528d 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -2361,6 +2361,16 @@ input formats output formats : `docx`, `odt`, `opendocument`, `html` +#### Extension: `native_numbering` #### + +Enables native numbering of figures and tables. Enumeration +starts at 1. + +This extension can be enabled/disabled for the following formats: + +output formats +: `odt`, `opendocument` + #### Extension: `styles` #### {#ext-styles} When converting from docx, read all docx styles as divs (for diff --git a/src/Text/Pandoc/Extensions.hs b/src/Text/Pandoc/Extensions.hs index 121b60e7b..4d85eb2e6 100644 --- a/src/Text/Pandoc/Extensions.hs +++ b/src/Text/Pandoc/Extensions.hs @@ -132,6 +132,7 @@ data Extension = | Ext_multiline_tables -- ^ Pandoc-style multiline tables | Ext_native_divs -- ^ Use Div blocks for contents of
tags | Ext_native_spans -- ^ Use Span inlines for contents of + | Ext_native_numbering -- ^ Use output format's native numbering for figures and tables | Ext_ntb -- ^ ConTeXt Natural Tables | Ext_old_dashes -- ^ -- = em, - before number = en | Ext_pandoc_title_block -- ^ Pandoc title block diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs index 3da778ae9..7a3aa4973 100644 --- a/src/Text/Pandoc/Writers/OpenDocument.hs +++ b/src/Text/Pandoc/Writers/OpenDocument.hs @@ -397,9 +397,9 @@ blockToOpenDocument o bs captionDoc <- if null c then return empty else inlinesToOpenDocument o c >>= - if True -- temporary: see #5474 - then unNumberedCaption "TableCaption" - else numberedTableCaption + if isEnabled Ext_native_numbering o + then numberedTableCaption + else unNumberedCaption "TableCaption" th <- if all null h then return empty else colHeadsToOpenDocument o (map fst paraHStyles) h @@ -412,9 +412,9 @@ blockToOpenDocument o bs | otherwise = do imageDoc <- withParagraphStyle o "FigureWithCaption" [Para [Image attr caption (source,title)]] captionDoc <- inlinesToOpenDocument o caption >>= - if True -- temporary: see #5474 - then unNumberedCaption "FigureCaption" - else numberedFigureCaption + if isEnabled Ext_native_numbering o + then numberedFigureCaption + else unNumberedCaption "FigureCaption" return $ imageDoc $$ captionDoc @@ -423,7 +423,7 @@ numberedTableCaption caption = do id' <- gets stTableCaptionId modify (\st -> st{ stTableCaptionId = id' + 1 }) capterm <- translateTerm Term.Table - return $ numberedCaption "Table" capterm "Table" id' caption + return $ numberedCaption "TableCaption" capterm "Table" id' caption numberedFigureCaption :: PandocMonad m => Doc Text -> OD m (Doc Text) numberedFigureCaption caption = do diff --git a/test/command/5474-figures.md b/test/command/5474-figures.md new file mode 100644 index 000000000..915bf3434 --- /dev/null +++ b/test/command/5474-figures.md @@ -0,0 +1,15 @@ +``` +% pandoc -t opendocument+native_numbering + +![First image](lalune.jpg) + +![Second image](lalune.jpg) + +^D + +Figure 1: First +image + +Figure 2: Second +image +``` diff --git a/test/command/5474-tables.md b/test/command/5474-tables.md new file mode 100644 index 000000000..3bd4f81e9 --- /dev/null +++ b/test/command/5474-tables.md @@ -0,0 +1,63 @@ +``` +% pandoc -t opendocument+native_numbering + Right Left +------- ------ + 12 11 + +: First table + + Right Left +------- ------ + 13 14 + +: Second Table +^D + + + + + + + Right + + + Left + + + + + + 12 + + + 11 + + + +Table 1: First +table + + + + + + + Right + + + Left + + + + + + 13 + + + 14 + + + +Table 2: Second +Table +``` -- cgit v1.2.3