From c0a8d5ac7213ac01b5f12dd7dfca66e6d8301f5f Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Sat, 28 Jun 2014 08:40:59 -0400 Subject: Docx Reader: All headers get auto id. Previously, only those with an anchor got an auto id. Now, all do, which puts it in line with pandoc's markdown extension. --- src/Text/Pandoc/Readers/Docx.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index 0607aac7f..71baa5dde 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -103,7 +103,6 @@ readDocx opts bytes = Just docx -> Pandoc nullMeta (docxToBlocks opts docx) Nothing -> error $ "couldn't parse docx file" - data DState = DState { docxAnchorMap :: M.Map String String } data DEnv = DEnv { docxOptions :: ReaderOptions @@ -321,6 +320,8 @@ dummyAnchors :: [String] dummyAnchors = ["_GoBack"] 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 @@ -330,6 +331,14 @@ makeHeaderAnchor (Header n (_, classes, kvs) ils) let newIdent = uniqueIdent ils (M.elems hdrIDMap) put DState{docxAnchorMap = M.insert ident newIdent hdrIDMap} return $ Header n (newIdent, classes, kvs) (ils \\ (x:xs)) +-- Otherwise we just give it a name, and register that name (associate +-- it with itself.) +makeHeaderAnchor (Header n (_, classes, kvs) ils) = + do + hdrIDMap <- gets docxAnchorMap + let newIdent = uniqueIdent ils (M.elems hdrIDMap) + put DState{docxAnchorMap = M.insert newIdent newIdent hdrIDMap} + return $ Header n (newIdent, classes, kvs) ils makeHeaderAnchor blk = return blk -- cgit v1.2.3