git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: Let headers use exisiting id.

Previously we always generated an id for headers (since they wouldn't bring one from Docx). Now we let it use an existing one if possible. This should allow us to recurs through anchor spans.

commit2893b0055aacb08e0970c6b7993f5385ef707884 authorJesse Rosenthal <jrosenthal@jhu.edu> dateSun 28 Aug 2016, 18:09 (10 years ago) parent62882f9
1 file changed+10−6
src/Text/Pandoc/Readers/Docx.hs+10−6
src/Text/Pandoc/Readers/Docx.hs+10−6
@@ -431,21 +431,25 @@ makeHeaderAnchor bs = case viewl $ unMany bs of
431431makeHeaderAnchor' :: Block -> DocxContext Block
432432-- If there is an anchor already there (an anchor span in the header,
433433-- to be exact), we rename and associate the new id with the old one.
434−makeHeaderAnchor' (Header n (_, classes, kvs) ils)
434+makeHeaderAnchor' (Header n (ident, classes, kvs) ils)
435435 | (c:_) <- filter isAnchorSpan ils
436− , (Span (ident, ["anchor"], _) cIls) <- c = do
436+ , (Span (anchIdent, ["anchor"], _) cIls) <- c = do
437437 hdrIDMap <- gets docxAnchorMap
438− let newIdent = uniqueIdent ils (Set.fromList $ M.elems hdrIDMap)
438+ let newIdent = if null ident
439+ then uniqueIdent ils (Set.fromList $ M.elems hdrIDMap)
440+ else ident
439441 newIls = concatMap f ils where f il | il == c = cIls
440442 | otherwise = [il]
441− modify $ \s -> s {docxAnchorMap = M.insert ident newIdent hdrIDMap}
443+ modify $ \s -> s {docxAnchorMap = M.insert anchIdent newIdent hdrIDMap}
442444 return $ Header n (newIdent, classes, kvs) newIls
443445-- Otherwise we just give it a name, and register that name (associate
444446-- it with itself.)
445−makeHeaderAnchor' (Header n (_, classes, kvs) ils) =
447+makeHeaderAnchor' (Header n (ident, classes, kvs) ils) =
446448 do
447449 hdrIDMap <- gets docxAnchorMap
448− let newIdent = uniqueIdent ils (Set.fromList $ M.elems hdrIDMap)
450+ let newIdent = if null ident
451+ then uniqueIdent ils (Set.fromList $ M.elems hdrIDMap)
452+ else ident
449453 modify $ \s -> s {docxAnchorMap = M.insert newIdent newIdent hdrIDMap}
450454 return $ Header n (newIdent, classes, kvs) ils
451455makeHeaderAnchor' blk = return blk