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.

     <w:fldSimple w:instr=" REF ref_superfig "><w:r><w:t>Figure X</w:t></w:r></w:fldSimple>

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.
This commit is contained in:
John MacFarlane 2021-09-12 15:30:29 -07:00
parent d43f9cf414
commit 6271b09c50
2 changed files with 6 additions and 3 deletions

View file

@ -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")
("<w:fldSimple w:instr=\"SEQ Figure"

Binary file not shown.