diff options
author | Jesse Rosenthal <jrosenthal@jhu.edu> | 2014-06-28 08:40:59 -0400 |
---|---|---|
committer | Jesse Rosenthal <jrosenthal@jhu.edu> | 2014-06-28 17:47:00 -0400 |
commit | c0a8d5ac7213ac01b5f12dd7dfca66e6d8301f5f (patch) | |
tree | 47474a8f335a572ddce06d55e30e7d5091a47ab2 /src/Text/Pandoc | |
parent | 7fc7e61745085ec87c074c147f372474074c46e3 (diff) | |
download | pandoc-c0a8d5ac7213ac01b5f12dd7dfca66e6d8301f5f.tar.gz |
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.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Readers/Docx.hs | 11 |
1 files changed, 10 insertions, 1 deletions
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 |