git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1374 from jkr/track-changes-options
9f69461John MacFarlane
@@ -308,6 +308,17 @@ Reader options
308`--tab-stop=`*NUMBER*
308`--tab-stop=`*NUMBER*
309: Specify the number of spaces per tab (default is 4).
309: Specify the number of spaces per tab (default is 4).
310
310
311+`--track-changes=`*accept|reject|all*
312+: Specifies what to do with insertions and deletions produced by the MS
313+ Word "track-changes" feature. *accept* (the default), inserts all
314+ insertions, and ignores all deletions. *reject* inserts all
315+ deletions and ignores insertions. *all* puts in both insertions
316+ and deletions, wrapped in spans with `insertion` and `deletion`
317+ classes, respectively. The author and time of change is
318+ included. *all* is useful for scripting: only accepting changes
319+ from a certain reviewer, say, or before a certain date. This
320+ option only affects the Docx reader.
321+
311General writer options
322General writer options
312----------------------
323----------------------
313
324
pandoc.hs+17
@@ -174,6 +174,7 @@ data Opt = Opt
174 , optTeXLigatures :: Bool -- ^ Use TeX ligatures for quotes/dashes
174 , optTeXLigatures :: Bool -- ^ Use TeX ligatures for quotes/dashes
175 , optDefaultImageExtension :: String -- ^ Default image extension
175 , optDefaultImageExtension :: String -- ^ Default image extension
176 , optTrace :: Bool -- ^ Print debug information
176 , optTrace :: Bool -- ^ Print debug information
177+ , optTrackChanges :: TrackChanges -- ^ Accept or reject MS Word track-changes.
177 }
178 }
178
179
179-- | Defaults for command-line options.
180-- | Defaults for command-line options.
@@ -230,6 +231,7 @@ defaultOpts = Opt
230 , optTeXLigatures = True
231 , optTeXLigatures = True
231 , optDefaultImageExtension = ""
232 , optDefaultImageExtension = ""
232 , optTrace = False
233 , optTrace = False
234+ , optTrackChanges = AcceptChanges
233 }
235 }
234
236
235-- | A list of functions, each transforming the options data structure
237-- | A list of functions, each transforming the options data structure
@@ -776,6 +778,19 @@ options =
776 (\opt -> return opt { optTrace = True }))
778 (\opt -> return opt { optTrace = True }))
777 "" -- "Turn on diagnostic tracing in readers."
779 "" -- "Turn on diagnostic tracing in readers."
778
780
781+ , Option "" ["track-changes"]
782+ (ReqArg
783+ (\arg opt -> do
784+ action <- case arg of
785+ "accept" -> return AcceptChanges
786+ "reject" -> return RejectChanges
787+ "all" -> return AllChanges
788+ _ -> err 6
789+ ("Unknown option for track-changes: " ++ arg)
790+ return opt { optTrackChanges = action })
791+ "accept|reject|all")
792+ "" -- "Accepting or reject MS Word track-changes.""
793+
779 , Option "" ["dump-args"]
794 , Option "" ["dump-args"]
780 (NoArg
795 (NoArg
781 (\opt -> return opt { optDumpArgs = True }))
796 (\opt -> return opt { optDumpArgs = True }))
@@ -973,6 +988,7 @@ main = do
973 , optTeXLigatures = texLigatures
988 , optTeXLigatures = texLigatures
974 , optDefaultImageExtension = defaultImageExtension
989 , optDefaultImageExtension = defaultImageExtension
975 , optTrace = trace
990 , optTrace = trace
991+ , optTrackChanges = trackChanges
976 } = opts
992 } = opts
977
993
978 when dumpArgs $
994 when dumpArgs $
@@ -1097,6 +1113,7 @@ main = do
1097 , readerApplyMacros = not laTeXOutput
1113 , readerApplyMacros = not laTeXOutput
1098 , readerDefaultImageExtension = defaultImageExtension
1114 , readerDefaultImageExtension = defaultImageExtension
1099 , readerTrace = trace
1115 , readerTrace = trace
1116+ , readerTrackChanges = trackChanges
1100 }
1117 }
1101
1118
1102 let writerOptions = def { writerStandalone = standalone',
1119 let writerOptions = def { writerStandalone = standalone',
src/Text/Pandoc/Options.hs+9
@@ -41,6 +41,7 @@ module Text.Pandoc.Options ( Extension(..)
41 , HTMLSlideVariant (..)
41 , HTMLSlideVariant (..)
42 , EPUBVersion (..)
42 , EPUBVersion (..)
43 , WriterOptions (..)
43 , WriterOptions (..)
44+ , TrackChanges (..)
44 , def
45 , def
45 , isEnabled
46 , isEnabled
46 ) where
47 ) where
@@ -211,6 +212,7 @@ data ReaderOptions = ReaderOptions{
211 -- indented code blocks
212 -- indented code blocks
212 , readerDefaultImageExtension :: String -- ^ Default extension for images
213 , readerDefaultImageExtension :: String -- ^ Default extension for images
213 , readerTrace :: Bool -- ^ Print debugging info
214 , readerTrace :: Bool -- ^ Print debugging info
215+ , readerTrackChanges :: TrackChanges
214} deriving (Show, Read)
216} deriving (Show, Read)
215
217
216instance Default ReaderOptions
218instance Default ReaderOptions
@@ -227,6 +229,7 @@ instance Default ReaderOptions
227 , readerIndentedCodeClasses = []
229 , readerIndentedCodeClasses = []
228 , readerDefaultImageExtension = ""
230 , readerDefaultImageExtension = ""
229 , readerTrace = False
231 , readerTrace = False
232+ , readerTrackChanges = AcceptChanges
230 }
233 }
231
234
232--
235--
@@ -264,6 +267,12 @@ data HTMLSlideVariant = S5Slides
264 | NoSlides
267 | NoSlides
265 deriving (Show, Read, Eq)
268 deriving (Show, Read, Eq)
266
269
270+-- | Options for accepting or rejecting MS Word track-changes.
271+data TrackChanges = AcceptChanges
272+ | RejectChanges
273+ | AllChanges
274+ deriving (Show, Read, Eq)
275+
267-- | Options for writers
276-- | Options for writers
268data WriterOptions = WriterOptions
277data WriterOptions = WriterOptions
269 { writerStandalone :: Bool -- ^ Include header and footer
278 { writerStandalone :: Bool -- ^ Include header and footer
src/Text/Pandoc/Readers/Docx.hs+16−3
@@ -234,9 +234,22 @@ runToInlines opts docx@(Docx _ notes _ _ _) (Endnote fnId) =
234
234
235parPartToInlines :: ReaderOptions -> Docx -> ParPart -> [Inline]
235parPartToInlines :: ReaderOptions -> Docx -> ParPart -> [Inline]
236parPartToInlines opts docx (PlainRun r) = runToInlines opts docx r
236parPartToInlines opts docx (PlainRun r) = runToInlines opts docx r
237−parPartToInlines opts docx (Insertion _ _ _ runs) =
237+parPartToInlines opts docx (Insertion _ author date runs) =
238+ case readerTrackChanges opts of
238− concatMap (runToInlines opts docx) runs
239+ AcceptChanges -> concatMap (runToInlines opts docx) runs
240+ RejectChanges -> []
241+ AllChanges ->
242+ [Span
243+ ("", ["insertion"], [("author", author), ("date", date)])
244+ (concatMap (runToInlines opts docx) runs)]
239−parPartToInlines _ _ (Deletion _ _ _ _) = []
245+parPartToInlines opts docx (Deletion _ author date runs) =
246+ case readerTrackChanges opts of
247+ AcceptChanges -> []
248+ RejectChanges -> concatMap (runToInlines opts docx) runs
249+ AllChanges ->
250+ [Span
251+ ("", ["deletion"], [("author", author), ("date", date)])
252+ (concatMap (runToInlines opts docx) runs)]
240parPartToInlines _ _ (BookMark _ anchor) | anchor `elem` dummyAnchors = []
253parPartToInlines _ _ (BookMark _ anchor) | anchor `elem` dummyAnchors = []
241parPartToInlines _ _ (BookMark _ anchor) = [Span (anchor, ["anchor"], []) []]
254parPartToInlines _ _ (BookMark _ anchor) = [Span (anchor, ["anchor"], []) []]
242parPartToInlines _ (Docx _ _ _ rels _) (Drawing relid) =
255parPartToInlines _ (Docx _ _ _ rels _) (Drawing relid) =
tests/Tests/Readers/Docx.hs+28−4
@@ -124,13 +124,37 @@ tests = [ testGroup "inlines"
124 ]
124 ]
125 , testGroup "track changes"
125 , testGroup "track changes"
126 [ testCompare
126 [ testCompare
127− "insert insertion (insertions only)"
127+ "insertion (default)"
128 "docx.track_changes_insertion.docx"
128 "docx.track_changes_insertion.docx"
129− "docx.track_changes_insertion_only_ins.native"
129+ "docx.track_changes_insertion_accept.native"
130+ , testCompareWithOpts def{readerTrackChanges=AcceptChanges}
131+ "insert insertion (accept)"
132+ "docx.track_changes_insertion.docx"
133+ "docx.track_changes_insertion_accept.native"
134+ , testCompareWithOpts def{readerTrackChanges=RejectChanges}
135+ "remove insertion (reject)"
136+ "docx.track_changes_insertion.docx"
137+ "docx.track_changes_insertion_reject.native"
130 , testCompare
138 , testCompare
131− "skip deletion (insertions only)"
139+ "deletion (default)"
140+ "docx.track_changes_deletion.docx"
141+ "docx.track_changes_deletion_accept.native"
142+ , testCompareWithOpts def{readerTrackChanges=AcceptChanges}
143+ "remove deletion (accept)"
144+ "docx.track_changes_deletion.docx"
145+ "docx.track_changes_deletion_accept.native"
146+ , testCompareWithOpts def{readerTrackChanges=RejectChanges}
147+ "insert deletion (reject)"
148+ "docx.track_changes_deletion.docx"
149+ "docx.track_changes_deletion_reject.native"
150+ , testCompareWithOpts def{readerTrackChanges=AllChanges}
151+ "keep insertion (all)"
152+ "docx.track_changes_deletion.docx"
153+ "docx.track_changes_deletion_all.native"
154+ , testCompareWithOpts def{readerTrackChanges=AllChanges}
155+ "keep deletion (all)"
132 "docx.track_changes_deletion.docx"
156 "docx.track_changes_deletion.docx"
133− "docx.track_changes_deletion_only_ins.native"
157+ "docx.track_changes_deletion_all.native"
134 ]
158 ]
135 ]
159 ]
136
160
tests/docx.track_changes_deletion_only_ins.native → tests/docx.track_changes_deletion_accept.nativerenamed

The content is the same.

tests/docx.track_changes_deletion_all.nativenew file+1
@@ -0,0 +1 @@
1+[Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "text",Space,Str "with",Space,Str "a",Span ("",["deletion"],[("author","eng-dept"),("date","2014-06-25T10:42:00Z")]) [Str "n",Space,Str "excessively",Space,Str "modified"],Space,Str "deletion."]]
tests/docx.track_changes_deletion_reject.nativenew file+1
@@ -0,0 +1 @@
1+[Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "text",Space,Str "with",Space,Str "an",Space,Str "excessively",Space,Str "modified",Space,Str "deletion."]]
tests/docx.track_changes_insertion_only_ins.native → tests/docx.track_changes_insertion_accept.nativerenamed

The content is the same.

tests/docx.track_changes_insertion_all.nativenew file+1
@@ -0,0 +1 @@
1+[Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "text",Space,Str "with",Space,Span ("",["insertion"],[("author","eng-dept"),("date","2014-06-25T10:40:00Z")]) [Str "two",Space,Str "exciting"],Space,Str "insertions."]]
tests/docx.track_changes_insertion_reject.nativenew file+1
@@ -0,0 +1 @@
1+[Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "text",Space,Str "with",Space,Str "insertions."]]