aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-06-28 15:00:25 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-06-28 15:00:25 -0700
commitce69021e42d7bf50deccba2a52ed4717f6ddac10 (patch)
treecec0417928f4a00d18b7a447948424f75eb90526 /src/Text
parent7fc7e61745085ec87c074c147f372474074c46e3 (diff)
parent7fb74d88fb3a55a91340c00b5f1e3c006314769d (diff)
downloadpandoc-ce69021e42d7bf50deccba2a52ed4717f6ddac10.tar.gz
Merge pull request #1379 from jkr/more_auto_id
Docx Reader: Extend auto id behavior to all headers
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/Docx.hs11
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