git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: Add warning for advanced comment formatting.

We can't guarantee we'll convert every comment correctly, though we'll do the best we can. This warns if the comment includes something other than Para or Plain.

commit032ba8dd0c235c47df1148f9bfa91dc277a09216 authorJesse Rosenthal <jrosenthal@jhu.edu> dateWed 22 Jun 2016, 15:39 (10 years ago) parent5f0cd89
1 file changed+18−2
src/Text/Pandoc/Readers/Docx.hs+18−2
src/Text/Pandoc/Readers/Docx.hs+18−2
@@ -139,6 +139,11 @@ type DocxContext = ExceptT PandocError (ReaderT DEnv (State DState))
139139evalDocxContext :: DocxContext a -> DEnv -> DState -> Either PandocError a
140140evalDocxContext ctx env st = flip evalState st . flip runReaderT env . runExceptT $ ctx
141141
142+addDocxWarning :: String -> DocxContext ()
143+addDocxWarning msg = do
144+ warnings <- gets docxWarnings
145+ modify $ \s -> s {docxWarnings = msg : warnings}
146+
142147-- This is empty, but we put it in for future-proofing.
143148spansToKeep :: [String]
144149spansToKeep = []
@@ -321,6 +326,17 @@ extentToAttr (Just (w, h)) =
321326 showDim d = show (d / 914400) ++ "in"
322327extentToAttr _ = nullAttr
323328
329+blocksToInlinesWarn :: String -> Blocks -> DocxContext Inlines
330+blocksToInlinesWarn cmtId blks = do
331+ let blkList = toList blks
332+ notParaOrPlain :: Block -> Bool
333+ notParaOrPlain (Para _) = False
334+ notParaOrPlain (Plain _) = False
335+ notParaOrPlain _ = True
336+ when (not $ null $ filter notParaOrPlain blkList)
337+ (addDocxWarning $ "Docx comment " ++ cmtId ++ " will not retain formatting")
338+ return $ fromList $ blocksToInlines blkList
339+
324340parPartToInlines :: ParPart -> DocxContext Inlines
325341parPartToInlines (PlainRun r) = runToInlines r
326342parPartToInlines (Insertion _ author date runs) = do
@@ -346,8 +362,8 @@ parPartToInlines (CommentStart cmtId author date bodyParts) = do
346362 case readerTrackChanges opts of
347363 AllChanges -> do
348364 blks <- smushBlocks <$> mapM bodyPartToBlocks bodyParts
349− let ils = fromList $ blocksToInlines $ toList blks
350− attr = ("", ["comment-start"], [("id", cmtId), ("author", author), ("date", date)])
365+ ils <- blocksToInlinesWarn cmtId blks
366+ let attr = ("", ["comment-start"], [("id", cmtId), ("author", author), ("date", date)])
351367 return $ spanWith attr ils
352368 _ -> return mempty
353369parPartToInlines (CommentEnd cmtId) = do