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.
This commit is contained in:
parent
2c466a15af
commit
4340bd52c4
5 changed files with 25 additions and 14 deletions
|
@ -3068,7 +3068,7 @@ starts at 1.
|
|||
This extension can be enabled/disabled for the following formats:
|
||||
|
||||
output formats
|
||||
: `odt`, `opendocument`
|
||||
: `odt`, `opendocument`, `docx`
|
||||
|
||||
#### Extension: `xrefs_name` ####
|
||||
|
||||
|
|
|
@ -475,6 +475,7 @@ getAllExtensions f = universalExtensions <> getAll f
|
|||
[ Ext_raw_markdown ]
|
||||
getAll "docx" = autoIdExtensions <> extensionsFromList
|
||||
[ Ext_empty_paragraphs
|
||||
, Ext_native_numbering
|
||||
, Ext_styles
|
||||
]
|
||||
getAll "opendocument" = extensionsFromList
|
||||
|
|
|
@ -869,14 +869,17 @@ blockToOpenXML' opts (Para [Image attr alt (src,T.stripPrefix "fig:" -> Just tit
|
|||
then return []
|
||||
else withParaPropM (pStyleM "Image Caption")
|
||||
$ blockToOpenXML opts
|
||||
(Para $ Span (figid,[],[])
|
||||
[Str (figname <> "\160"),
|
||||
RawInline (Format "openxml")
|
||||
("<w:fldSimple w:instr=\"SEQ Figure"
|
||||
<> " \\* ARABIC \"><w:r><w:t>"
|
||||
<> tshow fignum
|
||||
<> "</w:t></w:r></w:fldSimple>"),
|
||||
Str ":", Space] : alt)
|
||||
$ Para
|
||||
$ if isEnabled Ext_native_numbering opts
|
||||
then Span (figid,[],[])
|
||||
[Str (figname <> "\160"),
|
||||
RawInline (Format "openxml")
|
||||
("<w:fldSimple w:instr=\"SEQ Figure"
|
||||
<> " \\* ARABIC \"><w:r><w:t>"
|
||||
<> tshow fignum
|
||||
<> "</w:t></w:r></w:fldSimple>"),
|
||||
Str ":", Space] : alt
|
||||
else alt
|
||||
return $
|
||||
Elem (mknode "w:p" [] (map Elem paraProps ++ contents))
|
||||
: captionNode
|
||||
|
@ -922,7 +925,8 @@ blockToOpenXML' _ HorizontalRule = do
|
|||
("o:hralign","center"),
|
||||
("o:hrstd","t"),("o:hr","t")] () ]
|
||||
blockToOpenXML' opts (Table attr caption colspecs thead tbodies tfoot) =
|
||||
tableToOpenXML (blocksToOpenXML opts)
|
||||
tableToOpenXML opts
|
||||
(blocksToOpenXML opts)
|
||||
(Grid.toTable attr caption colspecs thead tbodies tfoot)
|
||||
blockToOpenXML' opts el
|
||||
| BulletList lst <- el = addOpenXMLList BulletMarker lst
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -31,7 +31,8 @@ tests = [ testGroup "inlines"
|
|||
"docx/golden/links.docx"
|
||||
, docxTest
|
||||
"inline image"
|
||||
def
|
||||
def{ writerExtensions =
|
||||
enableExtension Ext_native_numbering (writerExtensions def) }
|
||||
"docx/image_writer_test.native"
|
||||
"docx/golden/image.docx"
|
||||
, docxTest
|
||||
|
|
Loading…
Add table
Reference in a new issue