git.iko.soy/typeable/pandoc
on master help sign in
docx reader: enable warnings in top-level reader
5f0cd89Jesse Rosenthal
src/Text/Pandoc/Readers/Docx.hs+10−6
@@ -102,9 +102,9 @@ readDocxWithWarnings :: ReaderOptions
102 -> Either PandocError (Pandoc, MediaBag, [String])
102 -> Either PandocError (Pandoc, MediaBag, [String])
103readDocxWithWarnings opts bytes
103readDocxWithWarnings opts bytes
104 | Right archive <- toArchiveOrFail bytes
104 | Right archive <- toArchiveOrFail bytes
105− , Right (docx, warnings) <- archiveToDocxWithWarnings archive = do
105+ , Right (docx, parserWarnings) <- archiveToDocxWithWarnings archive = do
106− (meta, blks, mediaBag) <- docxToOutput opts docx
106+ (meta, blks, mediaBag, warnings) <- docxToOutput opts docx
107− return (Pandoc meta blks, mediaBag, warnings)
107+ return (Pandoc meta blks, mediaBag, parserWarnings ++ warnings)
108readDocxWithWarnings _ _ =
108readDocxWithWarnings _ _ =
109 Left (ParseFailure "couldn't parse docx file")
109 Left (ParseFailure "couldn't parse docx file")
110
110
@@ -118,12 +118,14 @@ readDocx opts bytes = do
118data DState = DState { docxAnchorMap :: M.Map String String
118data DState = DState { docxAnchorMap :: M.Map String String
119 , docxMediaBag :: MediaBag
119 , docxMediaBag :: MediaBag
120 , docxDropCap :: Inlines
120 , docxDropCap :: Inlines
121+ , docxWarnings :: [String]
121 }
122 }
122
123
123instance Default DState where
124instance Default DState where
124 def = DState { docxAnchorMap = M.empty
125 def = DState { docxAnchorMap = M.empty
125 , docxMediaBag = mempty
126 , docxMediaBag = mempty
126 , docxDropCap = mempty
127 , docxDropCap = mempty
128+ , docxWarnings = []
127 }
129 }
128
130
129data DEnv = DEnv { docxOptions :: ReaderOptions
131data DEnv = DEnv { docxOptions :: ReaderOptions
@@ -581,18 +583,20 @@ rewriteLink' il = return il
581rewriteLinks :: [Block] -> DocxContext [Block]
583rewriteLinks :: [Block] -> DocxContext [Block]
582rewriteLinks = mapM (walkM rewriteLink')
584rewriteLinks = mapM (walkM rewriteLink')
583
585
584−bodyToOutput :: Body -> DocxContext (Meta, [Block], MediaBag)
586+bodyToOutput :: Body -> DocxContext (Meta, [Block], MediaBag, [String])
585bodyToOutput (Body bps) = do
587bodyToOutput (Body bps) = do
586 let (metabps, blkbps) = sepBodyParts bps
588 let (metabps, blkbps) = sepBodyParts bps
587 meta <- bodyPartsToMeta metabps
589 meta <- bodyPartsToMeta metabps
588 blks <- smushBlocks <$> mapM bodyPartToBlocks blkbps
590 blks <- smushBlocks <$> mapM bodyPartToBlocks blkbps
589 blks' <- rewriteLinks $ blocksToDefinitions $ blocksToBullets $ toList blks
591 blks' <- rewriteLinks $ blocksToDefinitions $ blocksToBullets $ toList blks
590 mediaBag <- gets docxMediaBag
592 mediaBag <- gets docxMediaBag
593+ warnings <- gets docxWarnings
591 return $ (meta,
594 return $ (meta,
592 blks',
595 blks',
593− mediaBag)
596+ mediaBag,
597+ warnings)
594
598
595−docxToOutput :: ReaderOptions -> Docx -> Either PandocError (Meta, [Block], MediaBag)
599+docxToOutput :: ReaderOptions -> Docx -> Either PandocError (Meta, [Block], MediaBag, [String])
596docxToOutput opts (Docx (Document _ body)) =
600docxToOutput opts (Docx (Document _ body)) =
597 let dEnv = def { docxOptions = opts} in
601 let dEnv = def { docxOptions = opts} in
598 evalDocxContext (bodyToOutput body) dEnv def
602 evalDocxContext (bodyToOutput body) dEnv def