git.iko.soy/typeable/pandoc
on master help sign in
make makeHeaderAnchors make an auto id

Record relationship between original id and auto id, so we can fix links after.

commitb89a3ba2b1069205a308ad0f444457d595e5a77f authorJesse Rosenthal <jrosenthal@jhu.edu> dateSat 28 Jun 2014, 03:04 (12 years ago) parent5969baf
1 file changed+7−3
src/Text/Pandoc/Readers/Docx.hs+7−3
src/Text/Pandoc/Readers/Docx.hs+7−3
@@ -104,7 +104,7 @@ readDocx opts bytes =
104104 Nothing -> error $ "couldn't parse docx file"
105105
106106
107−data DState = DState { docxHdrLinks :: M.Map String String }
107+data DState = DState { docxHeaderAnchors :: M.Map String String }
108108
109109data DEnv = DEnv { docxOptions :: ReaderOptions
110110 , docxDocument :: Docx}
@@ -310,7 +310,11 @@ makeHeaderAnchor (Header n (_, classes, kvs) ils)
310310 | (x : xs) <- filter isAnchorSpan ils
311311 , (Span (ident, _, _) _) <- x
312312 , notElem ident dummyAnchors =
313− return $ Header n (ident, classes, kvs) (ils \\ (x:xs))
313+ do
314+ hdrIDMap <- gets docxHeaderAnchors
315+ let newIdent = uniqueIdent ils (M.elems hdrIDMap)
316+ put DState{docxHeaderAnchors = M.insert ident newIdent hdrIDMap}
317+ return $ Header n (newIdent, classes, kvs) (ils \\ (x:xs))
314318makeHeaderAnchor blk = return blk
315319
316320
@@ -432,7 +436,7 @@ bodyToBlocks (Body bps) = do
432436
433437docxToBlocks :: ReaderOptions -> Docx -> [Block]
434438docxToBlocks opts d@(Docx (Document _ body) _ _ _ _) =
435− let dState = DState { docxHdrLinks = M.empty }
439+ let dState = DState { docxHeaderAnchors = M.empty }
436440 dEnv = DEnv { docxOptions = opts
437441 , docxDocument = d}
438442 in