aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2014-06-29 08:14:36 -0400
committerJesse Rosenthal <jrosenthal@jhu.edu>2014-06-29 08:14:36 -0400
commitb1eba3c65ca2981c78b66d1ee9218f3dfeda89c7 (patch)
tree927074203625e7c3439a4acda9c4b6e7c0ec7029
parentce69021e42d7bf50deccba2a52ed4717f6ddac10 (diff)
downloadpandoc-b1eba3c65ca2981c78b66d1ee9218f3dfeda89c7.tar.gz
Docx Reader: Update state properly
Previously, a fresh state was created for the purpose of updating. In the future, when there is more than one field in the state, this obviously won't work.
-rw-r--r--src/Text/Pandoc/Readers/Docx.hs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs
index 71baa5dde..2e10ae3a4 100644
--- a/src/Text/Pandoc/Readers/Docx.hs
+++ b/src/Text/Pandoc/Readers/Docx.hs
@@ -110,6 +110,11 @@ data DEnv = DEnv { docxOptions :: ReaderOptions
type DocxContext = ReaderT DEnv (State DState)
+updateDState :: (DState -> DState) -> DocxContext ()
+updateDState f = do
+ st <- get
+ put $ f st
+
evalDocxContext :: DocxContext a -> DEnv -> DState -> a
evalDocxContext ctx env st = evalState (runReaderT ctx env) st
@@ -289,7 +294,7 @@ parPartToInlines (BookMark _ anchor) =
let newAnchor = case anchor `elem` (M.elems anchorMap) of
True -> uniqueIdent [Str anchor] (M.elems anchorMap)
False -> anchor
- put DState{ docxAnchorMap = M.insert anchor newAnchor anchorMap}
+ updateDState $ \s -> s { docxAnchorMap = M.insert anchor newAnchor anchorMap}
return [Span (anchor, ["anchor"], []) []]
parPartToInlines (Drawing relid) = do
(Docx _ _ _ rels _) <- asks docxDocument
@@ -329,7 +334,7 @@ makeHeaderAnchor (Header n (_, classes, kvs) ils)
do
hdrIDMap <- gets docxAnchorMap
let newIdent = uniqueIdent ils (M.elems hdrIDMap)
- put DState{docxAnchorMap = M.insert ident newIdent hdrIDMap}
+ updateDState $ \s -> s {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.)
@@ -337,7 +342,7 @@ 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}
+ updateDState $ \s -> s {docxAnchorMap = M.insert newIdent newIdent hdrIDMap}
return $ Header n (newIdent, classes, kvs) ils
makeHeaderAnchor blk = return blk