git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: Extract tracked changes type from parpart.
f6fde0aJesse Rosenthal
src/Text/Pandoc/Readers/Docx.hs+2−2
@@ -364,7 +364,7 @@ parPartToInlines parPart =
364
364
365parPartToInlines' :: PandocMonad m => ParPart -> DocxContext m Inlines
365parPartToInlines' :: PandocMonad m => ParPart -> DocxContext m Inlines
366parPartToInlines' (PlainRun r) = runToInlines r
366parPartToInlines' (PlainRun r) = runToInlines r
367−parPartToInlines' (Insertion _ author date runs) = do
367+parPartToInlines' (ChangedRuns (TrackedChange Insertion (ChangeInfo _ author date)) runs) = do
368 opts <- asks docxOptions
368 opts <- asks docxOptions
369 case readerTrackChanges opts of
369 case readerTrackChanges opts of
370 AcceptChanges -> smushInlines <$> mapM runToInlines runs
370 AcceptChanges -> smushInlines <$> mapM runToInlines runs
@@ -373,7 +373,7 @@ parPartToInlines' (Insertion _ author date runs) = do
373 ils <- smushInlines <$> mapM runToInlines runs
373 ils <- smushInlines <$> mapM runToInlines runs
374 let attr = ("", ["insertion"], [("author", author), ("date", date)])
374 let attr = ("", ["insertion"], [("author", author), ("date", date)])
375 return $ spanWith attr ils
375 return $ spanWith attr ils
376−parPartToInlines' (Deletion _ author date runs) = do
376+parPartToInlines' (ChangedRuns (TrackedChange Deletion (ChangeInfo _ author date)) runs) = do
377 opts <- asks docxOptions
377 opts <- asks docxOptions
378 case readerTrackChanges opts of
378 case readerTrackChanges opts of
379 AcceptChanges -> return mempty
379 AcceptChanges -> return mempty
src/Text/Pandoc/Readers/Docx/Parse.hs+17−4
@@ -51,6 +51,9 @@ module Text.Pandoc.Readers.Docx.Parse ( Docx(..)
51 , ParagraphStyle(..)
51 , ParagraphStyle(..)
52 , Row(..)
52 , Row(..)
53 , Cell(..)
53 , Cell(..)
54+ , TrackedChange(..)
55+ , ChangeType(..)
56+ , ChangeInfo(..)
54 , archiveToDocx
57 , archiveToDocx
55 , archiveToDocxWithWarnings
58 , archiveToDocxWithWarnings
56 ) where
59 ) where
@@ -198,6 +201,15 @@ data ParIndentation = ParIndentation { leftParIndent :: Maybe Integer
198 , hangingParIndent :: Maybe Integer}
201 , hangingParIndent :: Maybe Integer}
199 deriving Show
202 deriving Show
200
203
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+
201data ParagraphStyle = ParagraphStyle { pStyle :: [String]
213data ParagraphStyle = ParagraphStyle { pStyle :: [String]
202 , indentation :: Maybe ParIndentation
214 , indentation :: Maybe ParIndentation
203 , dropCap :: Bool
215 , dropCap :: Bool
@@ -241,8 +253,7 @@ data Cell = Cell [BodyPart]
241type Extent = Maybe (Double, Double)
253type Extent = Maybe (Double, Double)
242
254
243data ParPart = PlainRun Run
255data ParPart = PlainRun Run
244− | Insertion ChangeId Author ChangeDate [Run]
256+ | ChangedRuns TrackedChange [Run]
245− | Deletion ChangeId Author ChangeDate [Run]
246 | CommentStart CommentId Author CommentDate [BodyPart]
257 | CommentStart CommentId Author CommentDate [BodyPart]
247 | CommentEnd CommentId
258 | CommentEnd CommentId
248 | BookMark BookMarkId Anchor
259 | BookMark BookMarkId Anchor
@@ -732,14 +743,16 @@ elemToParPart ns element
732 , Just cAuthor <- findAttrByName ns "w" "author" element
743 , Just cAuthor <- findAttrByName ns "w" "author" element
733 , Just cDate <- findAttrByName ns "w" "date" element = do
744 , Just cDate <- findAttrByName ns "w" "date" element = do
734 runs <- mapD (elemToRun ns) (elChildren element)
745 runs <- mapD (elemToRun ns) (elChildren element)
746+ return $ ChangedRuns
735− return $ Insertion cId cAuthor cDate runs
747+ (TrackedChange Insertion (ChangeInfo cId cAuthor cDate)) runs
736elemToParPart ns element
748elemToParPart ns element
737 | isElem ns "w" "del" element || isElem ns "w" "moveFrom" element
749 | isElem ns "w" "del" element || isElem ns "w" "moveFrom" element
738 , Just cId <- findAttrByName ns "w" "id" element
750 , Just cId <- findAttrByName ns "w" "id" element
739 , Just cAuthor <- findAttrByName ns "w" "author" element
751 , Just cAuthor <- findAttrByName ns "w" "author" element
740 , Just cDate <- findAttrByName ns "w" "date" element = do
752 , Just cDate <- findAttrByName ns "w" "date" element = do
741 runs <- mapD (elemToRun ns) (elChildren element)
753 runs <- mapD (elemToRun ns) (elChildren element)
754+ return $ ChangedRuns
742− return $ Deletion cId cAuthor cDate runs
755+ (TrackedChange Deletion (ChangeInfo cId cAuthor cDate)) runs
743elemToParPart ns element
756elemToParPart ns element
744 | isElem ns "w" "smartTag" element = do
757 | isElem ns "w" "smartTag" element = do
745 runs <- mapD (elemToRun ns) (elChildren element)
758 runs <- mapD (elemToRun ns) (elChildren element)