From b89a3ba2b1069205a308ad0f444457d595e5a77f Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Sat, 28 Jun 2014 03:04:34 -0400 Subject: make makeHeaderAnchors make an auto id Record relationship between original id and auto id, so we can fix links after. --- src/Text/Pandoc/Readers/Docx.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/Text/Pandoc/Readers/Docx.hs') diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index bbe770f6e..a3053b72a 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -104,7 +104,7 @@ readDocx opts bytes = Nothing -> error $ "couldn't parse docx file" -data DState = DState { docxHdrLinks :: M.Map String String } +data DState = DState { docxHeaderAnchors :: M.Map String String } data DEnv = DEnv { docxOptions :: ReaderOptions , docxDocument :: Docx} @@ -310,7 +310,11 @@ makeHeaderAnchor (Header n (_, classes, kvs) ils) | (x : xs) <- filter isAnchorSpan ils , (Span (ident, _, _) _) <- x , notElem ident dummyAnchors = - return $ Header n (ident, classes, kvs) (ils \\ (x:xs)) + do + hdrIDMap <- gets docxHeaderAnchors + let newIdent = uniqueIdent ils (M.elems hdrIDMap) + put DState{docxHeaderAnchors = M.insert ident newIdent hdrIDMap} + return $ Header n (newIdent, classes, kvs) (ils \\ (x:xs)) makeHeaderAnchor blk = return blk @@ -432,7 +436,7 @@ bodyToBlocks (Body bps) = do docxToBlocks :: ReaderOptions -> Docx -> [Block] docxToBlocks opts d@(Docx (Document _ body) _ _ _ _) = - let dState = DState { docxHdrLinks = M.empty } + let dState = DState { docxHeaderAnchors = M.empty } dEnv = DEnv { docxOptions = opts , docxDocument = d} in -- cgit v1.2.3