diff options
author | Jesse Rosenthal <jrosenthal@jhu.edu> | 2016-06-22 15:16:40 -0400 |
---|---|---|
committer | Jesse Rosenthal <jrosenthal@jhu.edu> | 2016-06-23 10:50:46 -0400 |
commit | 5f0cd89129e4280bd4659adb6869d3be279f2195 (patch) | |
tree | 3d98de7de9144d04612cbc564c6e3c5810f0fb04 | |
parent | 8bb739f7ff353722981fe442ae0c137910604850 (diff) | |
download | pandoc-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.hs | 16 |
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 |