aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/Docx.hs
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2014-08-12 23:34:45 -0400
committerJesse Rosenthal <jrosenthal@jhu.edu>2014-08-12 23:41:57 -0400
commit378a795eaae7176426080c4164a66b33d511f87f (patch)
treeac5125577e5c67ca4f1397cab4e71fef0891df98 /src/Text/Pandoc/Readers/Docx.hs
parent85579052b5bb7196b62e9d9cd70e164498e49f6c (diff)
downloadpandoc-378a795eaae7176426080c4164a66b33d511f87f.tar.gz
Docx: More robust handling of multiple bookmarks in header.
Diffstat (limited to 'src/Text/Pandoc/Readers/Docx.hs')
-rw-r--r--src/Text/Pandoc/Readers/Docx.hs14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs
index 346d54bbe..28f49251c 100644
--- a/src/Text/Pandoc/Readers/Docx.hs
+++ b/src/Text/Pandoc/Readers/Docx.hs
@@ -402,7 +402,7 @@ parPartToInlines (PlainOMath exps) = do
isAnchorSpan :: Inline -> Bool
-isAnchorSpan (Span (ident, classes, kvs) ils) =
+isAnchorSpan (Span (_, classes, kvs) ils) =
classes == ["anchor"] &&
null kvs &&
null ils
@@ -415,14 +415,16 @@ makeHeaderAnchor :: Block -> DocxContext Block
-- If there is an anchor already there (an anchor span in the header,
-- to be exact), we rename and associate the new id with the old one.
makeHeaderAnchor (Header n (_, classes, kvs) ils)
- | (x : xs) <- filter isAnchorSpan ils
- , (Span (ident, _, _) _) <- x
- , notElem ident dummyAnchors =
+ | xs <- filter isAnchorSpan ils
+ , idents <- filter (\i -> notElem i dummyAnchors) $
+ map (\(Span (ident, _, _) _) -> ident) xs
+ , not $ null idents =
do
hdrIDMap <- gets docxAnchorMap
let newIdent = uniqueIdent ils (M.elems hdrIDMap)
- modify $ \s -> s {docxAnchorMap = M.insert ident newIdent hdrIDMap}
- return $ Header n (newIdent, classes, kvs) (ils \\ (x:xs))
+ newMap = M.fromList $ map (\i -> (i, newIdent)) idents
+ modify $ \s -> s {docxAnchorMap = M.union newMap hdrIDMap}
+ return $ Header n (newIdent, classes, kvs) (ils \\ xs)
-- Otherwise we just give it a name, and register that name (associate
-- it with itself.)
makeHeaderAnchor (Header n (_, classes, kvs) ils) =