Docx reader: fix anchor in header after anchor (#9626)

When the last parPart before a header was a bookmark, no span with an
anchor was added for a bookmark in the header. But the function that
adds header anchors to the anchor map, needs a span with an anchor.
So this commit adds that span.
This commit is contained in:
mbracke
2024-04-03 14:53:55 +02:00
committed by John MacFarlane
parent 3d902349d1
commit a331a1c00a
4 changed files with 13 additions and 4 deletions
+3 -4
View File
@@ -439,11 +439,10 @@ parPartToInlines' (BookMark _ anchor) =
-- avoid an extra pass.
immedPrevAnchor <- gets docxImmedPrevAnchor
case immedPrevAnchor of
Just prevAnchor -> do
unless inHdrBool
(modify $ \s -> s { docxAnchorMap = M.insert anchor prevAnchor anchorMap})
Just prevAnchor | not inHdrBool -> do
(modify $ \s -> s { docxAnchorMap = M.insert anchor prevAnchor anchorMap})
return mempty
Nothing -> do
_ -> do
exts <- asks (readerExtensions . docxOptions)
let newAnchor =
if not inHdrBool && anchor `elem` M.elems anchorMap
+4
View File
@@ -235,6 +235,10 @@ tests = [ testGroup "document"
"collapse overlapping targets (anchor spans)"
"docx/overlapping_targets.docx"
"docx/overlapping_targets.native"
, testCompare
"anchor in header after anchor"
"docx/anchor_header_after_anchor.docx"
"docx/anchor_header_after_anchor.native"
, testCompare
"text in shape format"
"docx/text_in_shape_format.docx"
Binary file not shown.
@@ -0,0 +1,6 @@
[Para [Link ("",[],[]) [Str "A",Space,Str "link",Space,Str "to",Space,Str "the",Space,Str "bookmark"] ("#referenced-title" , "")]
,Para [Strong [Str "Accomplices:"]]
,Para [Str "There",Space,Str "are",Space,Str "bookmarks",Space,Str "around",Space,Str "here."]
,Para []
,Header 1 ("referenced-title",[],[]) [Str "Referenced" ,Space ,Str "title"]
,Para [Str "Content"]]