@@ -83,7 +83,7 @@ import Text.Pandoc.Readers.Docx.Lists
83import Text.Pandoc.Readers.Docx.Combine
83import Text.Pandoc.Readers.Docx.Combine
84import Text.Pandoc.Shared
84import Text.Pandoc.Shared
85import Text.Pandoc.MediaBag (insertMedia, MediaBag)
85import Text.Pandoc.MediaBag (insertMedia, MediaBag)
86−import Data.List (delete, (\\), intersect)
86+import Data.List (delete, intersect)
87import Text.TeXMath (writeTeX)
87import Text.TeXMath (writeTeX)
88import Data.Default (Default)
88import Data.Default (Default)
89import qualified Data.ByteString.Lazy as B
89import qualified Data.ByteString.Lazy as B
@@ -412,10 +412,9 @@ parPartToInlines (PlainOMath exps) = do
412 return $ math $ writeTeX exps
412 return $ math $ writeTeX exps
414isAnchorSpan :: Inline -> Bool
414isAnchorSpan :: Inline -> Bool
415−isAnchorSpan (Span (_, classes, kvs) ils) =
415+isAnchorSpan (Span (_, classes, kvs) _) =
416 classes == ["anchor"] &&
416 classes == ["anchor"] &&
417− null kvs &&
417+ null kvs
419isAnchorSpan _ = False
418isAnchorSpan _ = False
421dummyAnchors :: [String]
420dummyAnchors :: [String]
@@ -433,12 +432,14 @@ makeHeaderAnchor' :: Block -> DocxContext Block
433-- 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,
434-- 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.
435makeHeaderAnchor' (Header n (_, classes, kvs) ils)
434makeHeaderAnchor' (Header n (_, classes, kvs) ils)
436− | (c:cs) <- filter isAnchorSpan ils
435+ | (c:_) <- filter isAnchorSpan ils
437− , (Span (ident, ["anchor"], _) _) <- c = do
436+ , (Span (ident, ["anchor"], _) cIls) <- c = do
438 hdrIDMap <- gets docxAnchorMap
437 hdrIDMap <- gets docxAnchorMap
439 let newIdent = uniqueIdent ils (Set.fromList $ M.elems hdrIDMap)
438 let newIdent = uniqueIdent ils (Set.fromList $ M.elems hdrIDMap)
439+ newIls = concatMap f ils where f il | il == c = cIls
440 modify $ \s -> s {docxAnchorMap = M.insert ident newIdent hdrIDMap}
441 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
442-- Otherwise we just give it a name, and register that name (associate
443-- Otherwise we just give it a name, and register that name (associate
443-- it with itself.)
444-- it with itself.)
444makeHeaderAnchor' (Header n (_, classes, kvs) ils) =
445makeHeaderAnchor' (Header n (_, classes, kvs) ils) =