@@ -402,7 +402,7 @@ parPartToInlines (PlainOMath exps) = do
402402
403403
404404isAnchorSpan :: Inline -> Bool
405−isAnchorSpan (Span (ident, classes, kvs) ils) =
405+isAnchorSpan (Span (_, classes, kvs) ils) =
406406 classes == ["anchor"] &&
407407 null kvs &&
408408 null ils
@@ -415,14 +415,16 @@ makeHeaderAnchor :: Block -> DocxContext Block
415415-- If there is an anchor already there (an anchor span in the header,
416416-- to be exact), we rename and associate the new id with the old one.
417417makeHeaderAnchor (Header n (_, classes, kvs) ils)
418− | (x : xs) <- filter isAnchorSpan ils
419− , (Span (ident, _, _) _) <- x
420− , notElem ident dummyAnchors =
418+ | xs <- filter isAnchorSpan ils
419+ , idents <- filter (\i -> notElem i dummyAnchors) $
420+ map (\(Span (ident, _, _) _) -> ident) xs
421+ , not $ null idents =
421422 do
422423 hdrIDMap <- gets docxAnchorMap
423424 let newIdent = uniqueIdent ils (M.elems hdrIDMap)
424− modify $ \s -> s {docxAnchorMap = M.insert ident newIdent hdrIDMap}
425− return $ Header n (newIdent, classes, kvs) (ils \\ (x:xs))
425+ newMap = M.fromList $ map (\i -> (i, newIdent)) idents
426+ modify $ \s -> s {docxAnchorMap = M.union newMap hdrIDMap}
427+ return $ Header n (newIdent, classes, kvs) (ils \\ xs)
426428-- Otherwise we just give it a name, and register that name (associate
427429-- it with itself.)
428430makeHeaderAnchor (Header n (_, classes, kvs) ils) =