@@ -431,21 +431,25 @@ makeHeaderAnchor bs = case viewl $ unMany bs of
431makeHeaderAnchor' :: Block -> DocxContext Block
431makeHeaderAnchor' :: Block -> DocxContext Block
432-- If there is an anchor already there (an anchor span in the header,
432-- If there is an anchor already there (an anchor span in the header,
433-- to be exact), we rename and associate the new id with the old one.
433-- 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)
435 | (c:_) <- filter isAnchorSpan ils
435 | (c:_) <- filter isAnchorSpan ils
436− , (Span (ident, ["anchor"], _) cIls) <- c = do
436+ , (Span (anchIdent, ["anchor"], _) cIls) <- c = do
437 hdrIDMap <- gets docxAnchorMap
437 hdrIDMap <- gets docxAnchorMap
438+ let newIdent = if null ident
438− let newIdent = uniqueIdent ils (Set.fromList $ M.elems hdrIDMap)
439+ then uniqueIdent ils (Set.fromList $ M.elems hdrIDMap)
439 newIls = concatMap f ils where f il | il == c = cIls
441 newIls = concatMap f ils where f il | il == c = cIls
440 | otherwise = [il]
442 | otherwise = [il]
441− modify $ \s -> s {docxAnchorMap = M.insert ident newIdent hdrIDMap}
443+ modify $ \s -> s {docxAnchorMap = M.insert anchIdent newIdent hdrIDMap}
442 return $ Header n (newIdent, classes, kvs) newIls
444 return $ Header n (newIdent, classes, kvs) newIls
443-- Otherwise we just give it a name, and register that name (associate
445-- Otherwise we just give it a name, and register that name (associate
444-- it with itself.)
446-- it with itself.)
445−makeHeaderAnchor' (Header n (_, classes, kvs) ils) =
447+makeHeaderAnchor' (Header n (ident, classes, kvs) ils) =
447 hdrIDMap <- gets docxAnchorMap
449 hdrIDMap <- gets docxAnchorMap
450+ let newIdent = if null ident
448− let newIdent = uniqueIdent ils (Set.fromList $ M.elems hdrIDMap)
451+ then uniqueIdent ils (Set.fromList $ M.elems hdrIDMap)
449 modify $ \s -> s {docxAnchorMap = M.insert newIdent newIdent hdrIDMap}
453 modify $ \s -> s {docxAnchorMap = M.insert newIdent newIdent hdrIDMap}
450 return $ Header n (newIdent, classes, kvs) ils
454 return $ Header n (newIdent, classes, kvs) ils
451makeHeaderAnchor' blk = return blk
455makeHeaderAnchor' blk = return blk