git.iko.soy/typeable/pandoc
on master help sign in
odt: Add external option for native numbering
8028de3Nils Carlson
MANUAL.txt+10
@@ -2361,6 +2361,16 @@ input formats
2361output formats
2361output formats
2362: `docx`, `odt`, `opendocument`, `html`
2362: `docx`, `odt`, `opendocument`, `html`
2363
2363
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+
2364#### Extension: `styles` #### {#ext-styles}
2374#### Extension: `styles` #### {#ext-styles}
2365
2375
2366When converting from docx, read all docx styles as divs (for
2376When converting from docx, read all docx styles as divs (for
src/Text/Pandoc/Extensions.hs+1
@@ -132,6 +132,7 @@ data Extension =
132 | Ext_multiline_tables -- ^ Pandoc-style multiline tables
132 | Ext_multiline_tables -- ^ Pandoc-style multiline tables
133 | Ext_native_divs -- ^ Use Div blocks for contents of <div> tags
133 | Ext_native_divs -- ^ Use Div blocks for contents of <div> tags
134 | Ext_native_spans -- ^ Use Span inlines for contents of <span>
134 | Ext_native_spans -- ^ Use Span inlines for contents of <span>
135+ | Ext_native_numbering -- ^ Use output format's native numbering for figures and tables
135 | Ext_ntb -- ^ ConTeXt Natural Tables
136 | Ext_ntb -- ^ ConTeXt Natural Tables
136 | Ext_old_dashes -- ^ -- = em, - before number = en
137 | Ext_old_dashes -- ^ -- = em, - before number = en
137 | Ext_pandoc_title_block -- ^ Pandoc title block
138 | Ext_pandoc_title_block -- ^ Pandoc title block
src/Text/Pandoc/Writers/OpenDocument.hs+7−7
@@ -397,9 +397,9 @@ blockToOpenDocument o bs
397 captionDoc <- if null c
397 captionDoc <- if null c
398 then return empty
398 then return empty
399 else inlinesToOpenDocument o c >>=
399 else inlinesToOpenDocument o c >>=
400− if True -- temporary: see #5474
400+ if isEnabled Ext_native_numbering o
401+ then numberedTableCaption
401− then unNumberedCaption "TableCaption"
402+ else unNumberedCaption "TableCaption"
402− else numberedTableCaption
403 th <- if all null h
403 th <- if all null h
404 then return empty
404 then return empty
405 else colHeadsToOpenDocument o (map fst paraHStyles) h
405 else colHeadsToOpenDocument o (map fst paraHStyles) h
@@ -412,9 +412,9 @@ blockToOpenDocument o bs
412 | otherwise = do
412 | otherwise = do
413 imageDoc <- withParagraphStyle o "FigureWithCaption" [Para [Image attr caption (source,title)]]
413 imageDoc <- withParagraphStyle o "FigureWithCaption" [Para [Image attr caption (source,title)]]
414 captionDoc <- inlinesToOpenDocument o caption >>=
414 captionDoc <- inlinesToOpenDocument o caption >>=
415− if True -- temporary: see #5474
415+ if isEnabled Ext_native_numbering o
416+ then numberedFigureCaption
416− then unNumberedCaption "FigureCaption"
417+ else unNumberedCaption "FigureCaption"
417− else numberedFigureCaption
418 return $ imageDoc $$ captionDoc
418 return $ imageDoc $$ captionDoc
419
419
420
420
@@ -423,7 +423,7 @@ numberedTableCaption caption = do
423 id' <- gets stTableCaptionId
423 id' <- gets stTableCaptionId
424 modify (\st -> st{ stTableCaptionId = id' + 1 })
424 modify (\st -> st{ stTableCaptionId = id' + 1 })
425 capterm <- translateTerm Term.Table
425 capterm <- translateTerm Term.Table
426− return $ numberedCaption "Table" capterm "Table" id' caption
426+ return $ numberedCaption "TableCaption" capterm "Table" id' caption
427
427
428numberedFigureCaption :: PandocMonad m => Doc Text -> OD m (Doc Text)
428numberedFigureCaption :: PandocMonad m => Doc Text -> OD m (Doc Text)
429numberedFigureCaption caption = do
429numberedFigureCaption 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+```