git.iko.soy/typeable/pandoc
on master help sign in
Docx writer: Implement track changes.

These have default authors and dates of "unknown" and timestamp-zero, respectively.

commite1bb28a3880e4d8b46f20510a89efb3830a590d6 authorJesse Rosenthal <jrosenthal@jhu.edu> dateMon 25 Aug 2014, 12:37 (12 years ago) parent9f8051d
1 file changed+40−9
src/Text/Pandoc/Writers/Docx.hs+40−9
src/Text/Pandoc/Writers/Docx.hs+40−9
@@ -1,4 +1,4 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
1+{-# LANGUAGE ScopedTypeVariables, PatternGuards #-}
22{-
33Copyright (C) 2012-2014 John MacFarlane <jgm@berkeley.edu>
44
@@ -94,6 +94,9 @@ data WriterState = WriterState{
9494 , stListLevel :: Int
9595 , stListNumId :: Int
9696 , stLists :: [ListMarker]
97+ , stInsId :: Int
98+ , stDelId :: Int
99+ , stInDel :: Bool
97100 }
98101
99102defaultWriterState :: WriterState
@@ -107,6 +110,9 @@ defaultWriterState = WriterState{
107110 , stListLevel = -1
108111 , stListNumId = 1
109112 , stLists = [NoMarker]
113+ , stInsId = 1
114+ , stDelId = 1
115+ , stInDel = False
110116 }
111117
112118type WS a = StateT WriterState IO a
@@ -735,20 +741,45 @@ withParaProp d p = do
735741formattedString :: String -> WS [Element]
736742formattedString str = do
737743 props <- getTextProps
744+ inDel <- gets stInDel
738745 return [ mknode "w:r" [] $
739746 props ++
740− [ mknode "w:t" [("xml:space","preserve")] str ] ]
747+ [ mknode (if inDel then "w:delText" else "w:t")
748+ [("xml:space","preserve")] str ] ]
741749
742750-- | Convert an inline element to OpenXML.
743751inlineToOpenXML :: WriterOptions -> Inline -> WS [Element]
744752inlineToOpenXML _ (Str str) = formattedString str
745753inlineToOpenXML opts Space = inlineToOpenXML opts (Str " ")
746−inlineToOpenXML opts (Span (_,classes,_) ils) = do
747− let off x = withTextProp (mknode x [("w:val","0")] ())
748− ((if "csl-no-emph" `elem` classes then off "w:i" else id) .
749− (if "csl-no-strong" `elem` classes then off "w:b" else id) .
750− (if "csl-no-smallcaps" `elem` classes then off "w:smallCaps" else id))
751− $ inlinesToOpenXML opts ils
754+inlineToOpenXML opts (Span (_,classes,kvs) ils)
755+ | "insertion" `elem` classes = do
756+ let author = fromMaybe "unknown" (lookup "author" kvs)
757+ date = fromMaybe "1969-12-31T19:00:00Z" (lookup "date" kvs)
758+ insId <- gets stInsId
759+ modify $ \s -> s{stInsId = (insId + 1)}
760+ x <- inlinesToOpenXML opts ils
761+ return [ mknode "w:ins" [("w:id", (show insId)),
762+ ("w:author", author),
763+ ("w:date", date)]
764+ x ]
765+ | "deletion" `elem` classes = do
766+ let author = fromMaybe "unknown" (lookup "author" kvs)
767+ date = fromMaybe "1969-12-31T19:00:00Z" (lookup "date" kvs)
768+ delId <- gets stDelId
769+ modify $ \s -> s{stDelId = (delId + 1)}
770+ modify $ \s -> s{stInDel = True}
771+ x <- inlinesToOpenXML opts ils
772+ modify $ \s -> s{stInDel = False}
773+ return [ mknode "w:del" [("w:id", (show delId)),
774+ ("w:author", author),
775+ ("w:date", date)]
776+ x ]
777+ | otherwise = do
778+ let off x = withTextProp (mknode x [("w:val","0")] ())
779+ ((if "csl-no-emph" `elem` classes then off "w:i" else id) .
780+ (if "csl-no-strong" `elem` classes then off "w:b" else id) .
781+ (if "csl-no-smallcaps" `elem` classes then off "w:smallCaps" else id))
782+ $ inlinesToOpenXML opts ils
752783inlineToOpenXML opts (Strong lst) =
753784 withTextProp (mknode "w:b" [] ()) $ inlinesToOpenXML opts lst
754785inlineToOpenXML opts (Emph lst) =
@@ -923,6 +954,6 @@ parseXml refArchive distArchive relpath =
923954fitToPage :: (Integer, Integer) -> (Integer, Integer)
924955fitToPage (x, y)
925956 --5440680 is the emu width size of a letter page in portrait, minus the margins
926− | x > 5440680 =
957+ | x > 5440680 =
927958 (5440680, round $ (5440680 / ((fromIntegral :: Integer -> Double) x)) * (fromIntegral y))
928959 | otherwise = (x, y)