From 6271b09c50444b107d8595f553700fa382718246 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 12 Sep 2021 15:30:29 -0700 Subject: [PATCH] Docx writer: make id used in native_numbering predictable. If the image has the id IMAGEID, then we use the id ref_IMAGEID for the figure number. Closes #7551. This allows one to create a filter that adds a figure number with figure name, e.g. Figure X For this to be possible it must be possible to predict the figure number id from the image id. If images lack an id, an id of the form `ref_fig1` is used. --- src/Text/Pandoc/Writers/Docx.hs | 9 ++++++--- test/docx/golden/image.docx | Bin 26811 -> 26816 bytes 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index 78d0840a4..686a2f662 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -854,11 +854,14 @@ blockToOpenXML' opts (Plain lst) = do then withParaProp prop block else block -- title beginning with fig: indicates that the image is a figure -blockToOpenXML' opts (Para [Image attr alt (src,T.stripPrefix "fig:" -> Just tit)]) = do +blockToOpenXML' opts (Para [Image attr@(imgident,_,_) alt + (src,T.stripPrefix "fig:" -> Just tit)]) = do setFirstPara fignum <- gets stNextFigureNum unless (null alt) $ modify $ \st -> st{ stNextFigureNum = fignum + 1 } - let figid = "fig" <> tshow fignum + let refid = if T.null imgident + then "ref_fig" <> tshow fignum + else "ref_" <> imgident figname <- translateTerm Term.Figure prop <- pStyleM $ if null alt @@ -872,7 +875,7 @@ blockToOpenXML' opts (Para [Image attr alt (src,T.stripPrefix "fig:" -> Just tit $ blockToOpenXML opts $ Para $ if isEnabled Ext_native_numbering opts - then Span (figid,[],[]) + then Span (refid,[],[]) [Str (figname <> "\160"), RawInline (Format "openxml") ("Y*ln(N?YMm=&X>7+?Ei-RF5e&-?v)y|3qae?HHvX&BZv3`0BFN=RY> zI1&kz*B!otZh%Q_Ti!z$8iw9>T(>;*T-PN4U=4f;-_QJxAv99BuqE5hmQd^A%#T>i zY4!K*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