From eda5540719e9771b48f15aa7f431033163e1f161 Mon Sep 17 00:00:00 2001 From: Diego Balseiro Date: Tue, 6 Oct 2020 23:03:00 -0500 Subject: DOCX reader: Allow empty dates in comments and tracked changes (#6726) For security reasons, some legal firms delete the date from comments and tracked changes. * Make date optional (Maybe) in tracked changes and comments datatypes * Add tests --- src/Text/Pandoc/Writers/Docx.hs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/Text/Pandoc/Writers') diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index a7720eb53..93f7dd799 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -1244,33 +1244,29 @@ inlineToOpenXML' opts (Span (ident,classes,kvs) ils) = do else id) getChangeAuthorDate = do defaultAuthor <- asks envChangesAuthor - defaultDate <- asks envChangesDate let author = fromMaybe defaultAuthor (lookup "author" kvs) - date = fromMaybe defaultDate (lookup "date" kvs) - return (author, date) + let mdate = lookup "date" kvs + return $ ("w:author", T.unpack author) : + maybe [] (\date -> [("w:date", T.unpack date)]) mdate insmod <- if "insertion" `elem` classes then do - (author, date) <- getChangeAuthorDate + changeAuthorDate <- getChangeAuthorDate insId <- gets stInsId modify $ \s -> s{stInsId = insId + 1} return $ \f -> do x <- f return [ mknode "w:ins" - [("w:id", show insId), - ("w:author", T.unpack author), - ("w:date", T.unpack date)] x ] + (("w:id", show insId) : changeAuthorDate) x] else return id delmod <- if "deletion" `elem` classes then do - (author, date) <- getChangeAuthorDate + changeAuthorDate <- getChangeAuthorDate delId <- gets stDelId modify $ \s -> s{stDelId = delId + 1} return $ \f -> local (\env->env{envInDel=True}) $ do x <- f return [mknode "w:del" - [("w:id", show delId), - ("w:author", T.unpack author), - ("w:date", T.unpack date)] x] + (("w:id", show delId) : changeAuthorDate) x] else return id contents <- insmod $ delmod $ dirmod $ stylemod $ pmod $ inlinesToOpenXML opts ils -- cgit v1.2.3