@@ -1,7 +1,7 @@
11{-# LANGUAGE CPP #-}
22{-# LANGUAGE OverloadedStrings #-}
33{-# LANGUAGE PatternGuards #-}
4−
4+{-# LANGUAGE MultiWayIf #-}
55{-
66Copyright (C) 2014-2017 Jesse Rosenthal <jrosenthal@jhu.edu>
77
@@ -127,6 +127,7 @@ data DState = DState { docxAnchorMap :: M.Map String String
127127 -- keep track of (numId, lvl) values for
128128 -- restarting
129129 , docxListState :: M.Map (String, String) Integer
130+ , docxPrevPara :: Inlines
130131 }
131132
132133instance Default DState where
@@ -137,6 +138,7 @@ instance Default DState where
137138 , docxDropCap = mempty
138139 , docxWarnings = []
139140 , docxListState = M.empty
141+ , docxPrevPara = mempty
140142 }
141143
142144data DEnv = DEnv { docxOptions :: ReaderOptions
@@ -562,16 +564,54 @@ bodyPartToBlocks (Paragraph pPr parparts)
562564 headerWith ("", delete style (pStyle pPr), []) n ils
563565 | otherwise = do
564566 ils <- (trimSps . smushInlines) <$> mapM parPartToInlines parparts
567+ prevParaIls <- gets docxPrevPara
565568 dropIls <- gets docxDropCap
566569 let ils' = dropIls <> ils
567570 if dropCap pPr
568571 then do modify $ \s -> s { docxDropCap = ils' }
569572 return mempty
570573 else do modify $ \s -> s { docxDropCap = mempty }
574+ let ils'' = prevParaIls <>
575+ (if isNull prevParaIls then mempty else space) <>
576+ ils'
571577 opts <- asks docxOptions
572− if isNull ils' && not (isEnabled Ext_empty_paragraphs opts)
573− then return mempty
574− else return $ parStyleToTransform pPr $ para ils'
578+ if | isNull ils'' && not (isEnabled Ext_empty_paragraphs opts) ->
579+ return mempty
580+ | Just (TrackedChange Insertion _) <- pChange pPr
581+ , AcceptChanges <- readerTrackChanges opts -> do
582+ modify $ \s -> s {docxPrevPara = mempty}
583+ return $ parStyleToTransform pPr $ para ils''
584+ | Just (TrackedChange Insertion _) <- pChange pPr
585+ , RejectChanges <- readerTrackChanges opts -> do
586+ modify $ \s -> s {docxPrevPara = ils''}
587+ return mempty
588+ | Just (TrackedChange Insertion cInfo) <- pChange pPr
589+ , AllChanges <- readerTrackChanges opts
590+ , ChangeInfo _ cAuthor cDate <- cInfo -> do
591+ let attr = ("", ["paragraph-insertion"], [("author", cAuthor), ("date", cDate)])
592+ insertMark = spanWith attr mempty
593+ return $
594+ parStyleToTransform pPr $
595+ para $ ils'' <> insertMark
596+ | Just (TrackedChange Deletion _) <- pChange pPr
597+ , AcceptChanges <- readerTrackChanges opts -> do
598+ modify $ \s -> s {docxPrevPara = ils''}
599+ return mempty
600+ | Just (TrackedChange Deletion _) <- pChange pPr
601+ , RejectChanges <- readerTrackChanges opts -> do
602+ modify $ \s -> s {docxPrevPara = mempty}
603+ return $ parStyleToTransform pPr $ para ils''
604+ | Just (TrackedChange Deletion cInfo) <- pChange pPr
605+ , AllChanges <- readerTrackChanges opts
606+ , ChangeInfo _ cAuthor cDate <- cInfo -> do
607+ let attr = ("", ["paragraph-deletion"], [("author", cAuthor), ("date", cDate)])
608+ insertMark = spanWith attr mempty
609+ return $
610+ parStyleToTransform pPr $
611+ para $ ils'' <> insertMark
612+ | otherwise -> do
613+ modify $ \s -> s {docxPrevPara = mempty}
614+ return $ parStyleToTransform pPr $ para ils''
575615bodyPartToBlocks (ListItem pPr numId lvl (Just levelInfo) parparts) = do
576616 -- We check whether this current numId has previously been used,
577617 -- since Docx expects us to pick up where we left off.