Skip to content

Commit

Permalink
Docx reader: fix anchor in header after anchor (#9626)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mbrackeantidot authored and jgm committed Apr 18, 2024
1 parent 3d90234 commit a331a1c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Text/Pandoc/Readers/Docx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/Tests/Readers/Docx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Binary file added test/docx/anchor_header_after_anchor.docx
Binary file not shown.
6 changes: 6 additions & 0 deletions test/docx/anchor_header_after_anchor.native
Original file line number Diff line number Diff line change
@@ -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"]]

0 comments on commit a331a1c

Please sign in to comment.