git.iko.soy/typeable/pandoc
on master help sign in
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.

commit8028de33220af0a43ac8d14021b7fa2b98b22d64 authorNils Carlson <nils.carlson@ludd.ltu.se> dateSat 21 Sep 2019, 20:12 (7 years ago) parent251e2b2
5 files changed+96−7
MANUAL.txt+10 src/Text/Pandoc/Extensions.hs+1 src/Text/Pandoc/Writers/OpenDocument.hs+7−7 test/command/5474-figures.md+15 test/command/5474-tables.md+63
MANUAL.txt+10
@@ -2361,6 +2361,16 @@ input formats
23612361output formats
23622362: `docx`, `odt`, `opendocument`, `html`
23632363
2364+#### Extension: `native_numbering` ####
2365+
2366+Enables native numbering of figures and tables. Enumeration
2367+starts at 1.
2368+
2369+This extension can be enabled/disabled for the following formats:
2370+
2371+output formats
2372+: `odt`, `opendocument`
2373+
23642374#### Extension: `styles` #### {#ext-styles}
23652375
23662376When converting from docx, read all docx styles as divs (for
src/Text/Pandoc/Extensions.hs+1
@@ -132,6 +132,7 @@ data Extension =
132132 | Ext_multiline_tables -- ^ Pandoc-style multiline tables
133133 | Ext_native_divs -- ^ Use Div blocks for contents of <div> tags
134134 | Ext_native_spans -- ^ Use Span inlines for contents of <span>
135+ | Ext_native_numbering -- ^ Use output format's native numbering for figures and tables
135136 | Ext_ntb -- ^ ConTeXt Natural Tables
136137 | Ext_old_dashes -- ^ -- = em, - before number = en
137138 | Ext_pandoc_title_block -- ^ Pandoc title block
src/Text/Pandoc/Writers/OpenDocument.hs+7−7
@@ -397,9 +397,9 @@ blockToOpenDocument o bs
397397 captionDoc <- if null c
398398 then return empty
399399 else inlinesToOpenDocument o c >>=
400− if True -- temporary: see #5474
401− then unNumberedCaption "TableCaption"
402− else numberedTableCaption
400+ if isEnabled Ext_native_numbering o
401+ then numberedTableCaption
402+ else unNumberedCaption "TableCaption"
403403 th <- if all null h
404404 then return empty
405405 else colHeadsToOpenDocument o (map fst paraHStyles) h
@@ -412,9 +412,9 @@ blockToOpenDocument o bs
412412 | otherwise = do
413413 imageDoc <- withParagraphStyle o "FigureWithCaption" [Para [Image attr caption (source,title)]]
414414 captionDoc <- inlinesToOpenDocument o caption >>=
415− if True -- temporary: see #5474
416− then unNumberedCaption "FigureCaption"
417− else numberedFigureCaption
415+ if isEnabled Ext_native_numbering o
416+ then numberedFigureCaption
417+ else unNumberedCaption "FigureCaption"
418418 return $ imageDoc $$ captionDoc
419419
420420
@@ -423,7 +423,7 @@ numberedTableCaption caption = do
423423 id' <- gets stTableCaptionId
424424 modify (\st -> st{ stTableCaptionId = id' + 1 })
425425 capterm <- translateTerm Term.Table
426− return $ numberedCaption "Table" capterm "Table" id' caption
426+ return $ numberedCaption "TableCaption" capterm "Table" id' caption
427427
428428numberedFigureCaption :: PandocMonad m => Doc Text -> OD m (Doc Text)
429429numberedFigureCaption caption = do
test/command/5474-figures.mdnew file+15
@@ -0,0 +1,15 @@
1+```
2+% pandoc -t opendocument+native_numbering
3+
4+![First image](lalune.jpg)
5+
6+![Second image](lalune.jpg)
7+
8+^D
9+<text:p text:style-name="FigureWithCaption"><draw:frame draw:name="img1"><draw:image xlink:href="lalune.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /></draw:frame></text:p>
10+<text:p text:style-name="FigureCaption">Figure <text:sequence text:ref-name="refIllustration0" text:name="Illustration" text:formula="ooow:Illustration+1" style:num-format="1">1</text:sequence>: First
11+image</text:p>
12+<text:p text:style-name="FigureWithCaption"><draw:frame draw:name="img2"><draw:image xlink:href="lalune.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /></draw:frame></text:p>
13+<text:p text:style-name="FigureCaption">Figure <text:sequence text:ref-name="refIllustration1" text:name="Illustration" text:formula="ooow:Illustration+1" style:num-format="1">2</text:sequence>: Second
14+image</text:p>
15+```
test/command/5474-tables.mdnew file+63
@@ -0,0 +1,63 @@
1+```
2+% pandoc -t opendocument+native_numbering
3+ Right Left
4+------- ------
5+ 12 11
6+
7+: First table
8+
9+ Right Left
10+------- ------
11+ 13 14
12+
13+: Second Table
14+^D
15+<table:table table:name="Table1" table:style-name="Table1">
16+ <table:table-column table:style-name="Table1.A" />
17+ <table:table-column table:style-name="Table1.B" />
18+ <table:table-header-rows>
19+ <table:table-row>
20+ <table:table-cell table:style-name="TableHeaderRowCell" office:value-type="string">
21+ <text:p text:style-name="P1">Right</text:p>
22+ </table:table-cell>
23+ <table:table-cell table:style-name="TableHeaderRowCell" office:value-type="string">
24+ <text:p text:style-name="Table_20_Heading">Left</text:p>
25+ </table:table-cell>
26+ </table:table-row>
27+ </table:table-header-rows>
28+ <table:table-row>
29+ <table:table-cell table:style-name="TableRowCell" office:value-type="string">
30+ <text:p text:style-name="P2">12</text:p>
31+ </table:table-cell>
32+ <table:table-cell table:style-name="TableRowCell" office:value-type="string">
33+ <text:p text:style-name="Table_20_Contents">11</text:p>
34+ </table:table-cell>
35+ </table:table-row>
36+</table:table>
37+<text:p text:style-name="TableCaption">Table <text:sequence text:ref-name="refTable0" text:name="Table" text:formula="ooow:Table+1" style:num-format="1">1</text:sequence>: First
38+table</text:p>
39+<table:table table:name="Table2" table:style-name="Table2">
40+ <table:table-column table:style-name="Table2.A" />
41+ <table:table-column table:style-name="Table2.B" />
42+ <table:table-header-rows>
43+ <table:table-row>
44+ <table:table-cell table:style-name="TableHeaderRowCell" office:value-type="string">
45+ <text:p text:style-name="P3">Right</text:p>
46+ </table:table-cell>
47+ <table:table-cell table:style-name="TableHeaderRowCell" office:value-type="string">
48+ <text:p text:style-name="Table_20_Heading">Left</text:p>
49+ </table:table-cell>
50+ </table:table-row>
51+ </table:table-header-rows>
52+ <table:table-row>
53+ <table:table-cell table:style-name="TableRowCell" office:value-type="string">
54+ <text:p text:style-name="P4">13</text:p>
55+ </table:table-cell>
56+ <table:table-cell table:style-name="TableRowCell" office:value-type="string">
57+ <text:p text:style-name="Table_20_Contents">14</text:p>
58+ </table:table-cell>
59+ </table:table-row>
60+</table:table>
61+<text:p text:style-name="TableCaption">Table <text:sequence text:ref-name="refTable1" text:name="Table" text:formula="ooow:Table+1" style:num-format="1">2</text:sequence>: Second
62+Table</text:p>
63+```