@@ -431,21 +431,25 @@ makeHeaderAnchor bs = case viewl $ unMany bs of
431431makeHeaderAnchor' :: Block -> DocxContext Block
432432-- If there is an anchor already there (an anchor span in the header,
433433-- to be exact), we rename and associate the new id with the old one.
434−makeHeaderAnchor' (Header n (_, classes, kvs) ils)
434+makeHeaderAnchor' (Header n (ident, classes, kvs) ils)
435435 | (c:_) <- filter isAnchorSpan ils
436− , (Span (ident, ["anchor"], _) cIls) <- c = do
436+ , (Span (anchIdent, ["anchor"], _) cIls) <- c = do
437437 hdrIDMap <- gets docxAnchorMap
438− let newIdent = uniqueIdent ils (Set.fromList $ M.elems hdrIDMap)
438+ let newIdent = if null ident
439+ then uniqueIdent ils (Set.fromList $ M.elems hdrIDMap)
440+ else ident
439441 newIls = concatMap f ils where f il | il == c = cIls
440442 | otherwise = [il]
441− modify $ \s -> s {docxAnchorMap = M.insert ident newIdent hdrIDMap}
443+ modify $ \s -> s {docxAnchorMap = M.insert anchIdent newIdent hdrIDMap}
442444 return $ Header n (newIdent, classes, kvs) newIls
443445-- Otherwise we just give it a name, and register that name (associate
444446-- it with itself.)
445−makeHeaderAnchor' (Header n (_, classes, kvs) ils) =
447+makeHeaderAnchor' (Header n (ident, classes, kvs) ils) =
446448 do
447449 hdrIDMap <- gets docxAnchorMap
448− let newIdent = uniqueIdent ils (Set.fromList $ M.elems hdrIDMap)
450+ let newIdent = if null ident
451+ then uniqueIdent ils (Set.fromList $ M.elems hdrIDMap)
452+ else ident
449453 modify $ \s -> s {docxAnchorMap = M.insert newIdent newIdent hdrIDMap}
450454 return $ Header n (newIdent, classes, kvs) ils
451455makeHeaderAnchor' blk = return blk