@@ -1,4 +1,4 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
1+{-# LANGUAGE ScopedTypeVariables, PatternGuards #-}
3Copyright (C) 2012-2014 John MacFarlane <jgm@berkeley.edu>
3Copyright (C) 2012-2014 John MacFarlane <jgm@berkeley.edu>
@@ -94,6 +94,9 @@ data WriterState = WriterState{
94 , stListLevel :: Int
94 , stListLevel :: Int
95 , stListNumId :: Int
95 , stListNumId :: Int
96 , stLists :: [ListMarker]
96 , stLists :: [ListMarker]
99defaultWriterState :: WriterState
102defaultWriterState :: WriterState
@@ -107,6 +110,9 @@ defaultWriterState = WriterState{
107 , stListLevel = -1
110 , stListLevel = -1
108 , stListNumId = 1
111 , stListNumId = 1
109 , stLists = [NoMarker]
112 , stLists = [NoMarker]
112type WS a = StateT WriterState IO a
118type WS a = StateT WriterState IO a
@@ -735,20 +741,45 @@ withParaProp d p = do
735formattedString :: String -> WS [Element]
741formattedString :: String -> WS [Element]
736formattedString str = do
742formattedString str = do
737 props <- getTextProps
743 props <- getTextProps
744+ inDel <- gets stInDel
738 return [ mknode "w:r" [] $
745 return [ mknode "w:r" [] $
747+ [ mknode (if inDel then "w:delText" else "w:t")
740− [ mknode "w:t" [("xml:space","preserve")] str ] ]
748+ [("xml:space","preserve")] str ] ]
742-- | Convert an inline element to OpenXML.
750-- | Convert an inline element to OpenXML.
743inlineToOpenXML :: WriterOptions -> Inline -> WS [Element]
751inlineToOpenXML :: WriterOptions -> Inline -> WS [Element]
744inlineToOpenXML _ (Str str) = formattedString str
752inlineToOpenXML _ (Str str) = formattedString str
745inlineToOpenXML opts Space = inlineToOpenXML opts (Str " ")
753inlineToOpenXML opts Space = inlineToOpenXML opts (Str " ")
746−inlineToOpenXML opts (Span (_,classes,_) ils) = do
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),
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),
747− let off x = withTextProp (mknode x [("w:val","0")] ())
778+ let off x = withTextProp (mknode x [("w:val","0")] ())
748− ((if "csl-no-emph" `elem` classes then off "w:i" else id) .
779+ ((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) .
780+ (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))
781+ (if "csl-no-smallcaps" `elem` classes then off "w:smallCaps" else id))
751− $ inlinesToOpenXML opts ils
782+ $ inlinesToOpenXML opts ils
752inlineToOpenXML opts (Strong lst) =
783inlineToOpenXML opts (Strong lst) =
753 withTextProp (mknode "w:b" [] ()) $ inlinesToOpenXML opts lst
784 withTextProp (mknode "w:b" [] ()) $ inlinesToOpenXML opts lst
754inlineToOpenXML opts (Emph lst) =
785inlineToOpenXML opts (Emph lst) =
@@ -923,6 +954,6 @@ parseXml refArchive distArchive relpath =
923fitToPage :: (Integer, Integer) -> (Integer, Integer)
954fitToPage :: (Integer, Integer) -> (Integer, Integer)
924fitToPage (x, y)
955fitToPage (x, y)
925 --5440680 is the emu width size of a letter page in portrait, minus the margins
956 --5440680 is the emu width size of a letter page in portrait, minus the margins
926− | x > 5440680 =
957+ | x > 5440680 =
927 (5440680, round $ (5440680 / ((fromIntegral :: Integer -> Double) x)) * (fromIntegral y))
958 (5440680, round $ (5440680 / ((fromIntegral :: Integer -> Double) x)) * (fromIntegral y))
928 | otherwise = (x, y)
959 | otherwise = (x, y)