diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index 0c75fdb08..7752092b1 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -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 diff --git a/test/Tests/Readers/Docx.hs b/test/Tests/Readers/Docx.hs index 05b69abf6..b2aa36560 100644 --- a/test/Tests/Readers/Docx.hs +++ b/test/Tests/Readers/Docx.hs @@ -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" diff --git a/test/docx/anchor_header_after_anchor.docx b/test/docx/anchor_header_after_anchor.docx new file mode 100644 index 000000000..e0b7da261 Binary files /dev/null and b/test/docx/anchor_header_after_anchor.docx differ diff --git a/test/docx/anchor_header_after_anchor.native b/test/docx/anchor_header_after_anchor.native new file mode 100644 index 000000000..4a1f284f9 --- /dev/null +++ b/test/docx/anchor_header_after_anchor.native @@ -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"]]