git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: Extract tracked changes type from parpart.

We're going to want to use it elsewhere as well, in upcoming tracking of paragraph insertion/deletion.

commitf6fde0ae5ea21d91d610c21c0488029f9c26ca3f authorJesse Rosenthal <jrosenthal@jhu.edu> dateTue 2 Jan 2018, 07:50 (9 years ago) parentb9d7342
2 files changed+19−6
src/Text/Pandoc/Readers/Docx.hs+2−2 src/Text/Pandoc/Readers/Docx/Parse.hs+17−4
src/Text/Pandoc/Readers/Docx.hs+2−2
@@ -364,7 +364,7 @@ parPartToInlines parPart =
364364
365365parPartToInlines' :: PandocMonad m => ParPart -> DocxContext m Inlines
366366parPartToInlines' (PlainRun r) = runToInlines r
367−parPartToInlines' (Insertion _ author date runs) = do
367+parPartToInlines' (ChangedRuns (TrackedChange Insertion (ChangeInfo _ author date)) runs) = do
368368 opts <- asks docxOptions
369369 case readerTrackChanges opts of
370370 AcceptChanges -> smushInlines <$> mapM runToInlines runs
@@ -373,7 +373,7 @@ parPartToInlines' (Insertion _ author date runs) = do
373373 ils <- smushInlines <$> mapM runToInlines runs
374374 let attr = ("", ["insertion"], [("author", author), ("date", date)])
375375 return $ spanWith attr ils
376−parPartToInlines' (Deletion _ author date runs) = do
376+parPartToInlines' (ChangedRuns (TrackedChange Deletion (ChangeInfo _ author date)) runs) = do
377377 opts <- asks docxOptions
378378 case readerTrackChanges opts of
379379 AcceptChanges -> return mempty
src/Text/Pandoc/Readers/Docx/Parse.hs+17−4
@@ -51,6 +51,9 @@ module Text.Pandoc.Readers.Docx.Parse ( Docx(..)
5151 , ParagraphStyle(..)
5252 , Row(..)
5353 , Cell(..)
54+ , TrackedChange(..)
55+ , ChangeType(..)
56+ , ChangeInfo(..)
5457 , archiveToDocx
5558 , archiveToDocxWithWarnings
5659 ) where
@@ -198,6 +201,15 @@ data ParIndentation = ParIndentation { leftParIndent :: Maybe Integer
198201 , hangingParIndent :: Maybe Integer}
199202 deriving Show
200203
204+data ChangeType = Insertion | Deletion
205+ deriving Show
206+
207+data ChangeInfo = ChangeInfo ChangeId Author ChangeDate
208+ deriving Show
209+
210+data TrackedChange = TrackedChange ChangeType ChangeInfo
211+ deriving Show
212+
201213data ParagraphStyle = ParagraphStyle { pStyle :: [String]
202214 , indentation :: Maybe ParIndentation
203215 , dropCap :: Bool
@@ -241,8 +253,7 @@ data Cell = Cell [BodyPart]
241253type Extent = Maybe (Double, Double)
242254
243255data ParPart = PlainRun Run
244− | Insertion ChangeId Author ChangeDate [Run]
245− | Deletion ChangeId Author ChangeDate [Run]
256+ | ChangedRuns TrackedChange [Run]
246257 | CommentStart CommentId Author CommentDate [BodyPart]
247258 | CommentEnd CommentId
248259 | BookMark BookMarkId Anchor
@@ -732,14 +743,16 @@ elemToParPart ns element
732743 , Just cAuthor <- findAttrByName ns "w" "author" element
733744 , Just cDate <- findAttrByName ns "w" "date" element = do
734745 runs <- mapD (elemToRun ns) (elChildren element)
735− return $ Insertion cId cAuthor cDate runs
746+ return $ ChangedRuns
747+ (TrackedChange Insertion (ChangeInfo cId cAuthor cDate)) runs
736748elemToParPart ns element
737749 | isElem ns "w" "del" element || isElem ns "w" "moveFrom" element
738750 , Just cId <- findAttrByName ns "w" "id" element
739751 , Just cAuthor <- findAttrByName ns "w" "author" element
740752 , Just cDate <- findAttrByName ns "w" "date" element = do
741753 runs <- mapD (elemToRun ns) (elChildren element)
742− return $ Deletion cId cAuthor cDate runs
754+ return $ ChangedRuns
755+ (TrackedChange Deletion (ChangeInfo cId cAuthor cDate)) runs
743756elemToParPart ns element
744757 | isElem ns "w" "smartTag" element = do
745758 runs <- mapD (elemToRun ns) (elChildren element)