@@ -83,7 +83,7 @@ import Text.Pandoc.Readers.Docx.Lists
8383import Text.Pandoc.Readers.Docx.Combine
8484import Text.Pandoc.Shared
8585import Text.Pandoc.MediaBag (insertMedia, MediaBag)
86−import Data.List (delete, (\\), intersect)
86+import Data.List (delete, intersect)
8787import Text.TeXMath (writeTeX)
8888import Data.Default (Default)
8989import qualified Data.ByteString.Lazy as B
@@ -412,10 +412,9 @@ parPartToInlines (PlainOMath exps) = do
412412 return $ math $ writeTeX exps
413413
414414isAnchorSpan :: Inline -> Bool
415−isAnchorSpan (Span (_, classes, kvs) ils) =
415+isAnchorSpan (Span (_, classes, kvs) _) =
416416 classes == ["anchor"] &&
417− null kvs &&
418− null ils
417+ null kvs
419418isAnchorSpan _ = False
420419
421420dummyAnchors :: [String]
@@ -433,12 +432,14 @@ makeHeaderAnchor' :: Block -> DocxContext Block
433432-- If there is an anchor already there (an anchor span in the header,
434433-- to be exact), we rename and associate the new id with the old one.
435434makeHeaderAnchor' (Header n (_, classes, kvs) ils)
436− | (c:cs) <- filter isAnchorSpan ils
437− , (Span (ident, ["anchor"], _) _) <- c = do
435+ | (c:_) <- filter isAnchorSpan ils
436+ , (Span (ident, ["anchor"], _) cIls) <- c = do
438437 hdrIDMap <- gets docxAnchorMap
439438 let newIdent = uniqueIdent ils (Set.fromList $ M.elems hdrIDMap)
439+ newIls = concatMap f ils where f il | il == c = cIls
440+ | otherwise = [il]
440441 modify $ \s -> s {docxAnchorMap = M.insert ident newIdent hdrIDMap}
441− return $ Header n (newIdent, classes, kvs) (ils \\ (c:cs))
442+ return $ Header n (newIdent, classes, kvs) newIls
442443-- Otherwise we just give it a name, and register that name (associate
443444-- it with itself.)
444445makeHeaderAnchor' (Header n (_, classes, kvs) ils) =