aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2016-06-22 15:16:40 -0400
committerJesse Rosenthal <jrosenthal@jhu.edu>2016-06-23 10:50:46 -0400
commit5f0cd89129e4280bd4659adb6869d3be279f2195 (patch)
tree3d98de7de9144d04612cbc564c6e3c5810f0fb04
parent8bb739f7ff353722981fe442ae0c137910604850 (diff)
downloadpandoc-5f0cd89129e4280bd4659adb6869d3be279f2195.tar.gz
docx reader: enable warnings in top-level reader
Previously we had only allowed for warnings in the parser. Now we allow for them in the `Docx.hs` as well. The warnings are simply concatenated.
-rw-r--r--src/Text/Pandoc/Readers/Docx.hs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs
index 610477f02..313610783 100644
--- a/src/Text/Pandoc/Readers/Docx.hs
+++ b/src/Text/Pandoc/Readers/Docx.hs
@@ -102,9 +102,9 @@ readDocxWithWarnings :: ReaderOptions
-> Either PandocError (Pandoc, MediaBag, [String])
readDocxWithWarnings opts bytes
| Right archive <- toArchiveOrFail bytes
- , Right (docx, warnings) <- archiveToDocxWithWarnings archive = do
- (meta, blks, mediaBag) <- docxToOutput opts docx
- return (Pandoc meta blks, mediaBag, warnings)
+ , Right (docx, parserWarnings) <- archiveToDocxWithWarnings archive = do
+ (meta, blks, mediaBag, warnings) <- docxToOutput opts docx
+ return (Pandoc meta blks, mediaBag, parserWarnings ++ warnings)
readDocxWithWarnings _ _ =
Left (ParseFailure "couldn't parse docx file")
@@ -118,12 +118,14 @@ readDocx opts bytes = do
data DState = DState { docxAnchorMap :: M.Map String String
, docxMediaBag :: MediaBag
, docxDropCap :: Inlines
+ , docxWarnings :: [String]
}
instance Default DState where
def = DState { docxAnchorMap = M.empty
, docxMediaBag = mempty
, docxDropCap = mempty
+ , docxWarnings = []
}
data DEnv = DEnv { docxOptions :: ReaderOptions
@@ -581,18 +583,20 @@ rewriteLink' il = return il
rewriteLinks :: [Block] -> DocxContext [Block]
rewriteLinks = mapM (walkM rewriteLink')
-bodyToOutput :: Body -> DocxContext (Meta, [Block], MediaBag)
+bodyToOutput :: Body -> DocxContext (Meta, [Block], MediaBag, [String])
bodyToOutput (Body bps) = do
let (metabps, blkbps) = sepBodyParts bps
meta <- bodyPartsToMeta metabps
blks <- smushBlocks <$> mapM bodyPartToBlocks blkbps
blks' <- rewriteLinks $ blocksToDefinitions $ blocksToBullets $ toList blks
mediaBag <- gets docxMediaBag
+ warnings <- gets docxWarnings
return $ (meta,
blks',
- mediaBag)
+ mediaBag,
+ warnings)
-docxToOutput :: ReaderOptions -> Docx -> Either PandocError (Meta, [Block], MediaBag)
+docxToOutput :: ReaderOptions -> Docx -> Either PandocError (Meta, [Block], MediaBag, [String])
docxToOutput opts (Docx (Document _ body)) =
let dEnv = def { docxOptions = opts} in
evalDocxContext (bodyToOutput body) dEnv def