git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1374 from jkr/track-changes-options

Track changes with options

commit9f694619cd62992097df25690b1fbfe964d6c32e authorJohn MacFarlane <jgm@berkeley.edu> dateWed 25 Jun 2014, 23:51 (12 years ago) parent2b958a274676df
11 files changed+85−7
README+11 pandoc.hs+17 src/Text/Pandoc/Options.hs+9 src/Text/Pandoc/Readers/Docx.hs+16−3 tests/Tests/Readers/Docx.hs+28−4 tests/docx.track_changes_deletion_only_ins.native → tests/docx.track_changes_deletion_accept.native tests/docx.track_changes_deletion_all.native+1 tests/docx.track_changes_deletion_reject.native+1 tests/docx.track_changes_insertion_only_ins.native → tests/docx.track_changes_insertion_accept.native tests/docx.track_changes_insertion_all.native+1 tests/docx.track_changes_insertion_reject.native+1
README+11
@@ -308,6 +308,17 @@ Reader options
308308`--tab-stop=`*NUMBER*
309309: Specify the number of spaces per tab (default is 4).
310310
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+
311322General writer options
312323----------------------
313324
pandoc.hs+17
@@ -174,6 +174,7 @@ data Opt = Opt
174174 , optTeXLigatures :: Bool -- ^ Use TeX ligatures for quotes/dashes
175175 , optDefaultImageExtension :: String -- ^ Default image extension
176176 , optTrace :: Bool -- ^ Print debug information
177+ , optTrackChanges :: TrackChanges -- ^ Accept or reject MS Word track-changes.
177178 }
178179
179180-- | Defaults for command-line options.
@@ -230,6 +231,7 @@ defaultOpts = Opt
230231 , optTeXLigatures = True
231232 , optDefaultImageExtension = ""
232233 , optTrace = False
234+ , optTrackChanges = AcceptChanges
233235 }
234236
235237-- | A list of functions, each transforming the options data structure
@@ -776,6 +778,19 @@ options =
776778 (\opt -> return opt { optTrace = True }))
777779 "" -- "Turn on diagnostic tracing in readers."
778780
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+
779794 , Option "" ["dump-args"]
780795 (NoArg
781796 (\opt -> return opt { optDumpArgs = True }))
@@ -973,6 +988,7 @@ main = do
973988 , optTeXLigatures = texLigatures
974989 , optDefaultImageExtension = defaultImageExtension
975990 , optTrace = trace
991+ , optTrackChanges = trackChanges
976992 } = opts
977993
978994 when dumpArgs $
@@ -1097,6 +1113,7 @@ main = do
10971113 , readerApplyMacros = not laTeXOutput
10981114 , readerDefaultImageExtension = defaultImageExtension
10991115 , readerTrace = trace
1116+ , readerTrackChanges = trackChanges
11001117 }
11011118
11021119 let writerOptions = def { writerStandalone = standalone',
src/Text/Pandoc/Options.hs+9
@@ -41,6 +41,7 @@ module Text.Pandoc.Options ( Extension(..)
4141 , HTMLSlideVariant (..)
4242 , EPUBVersion (..)
4343 , WriterOptions (..)
44+ , TrackChanges (..)
4445 , def
4546 , isEnabled
4647 ) where
@@ -211,6 +212,7 @@ data ReaderOptions = ReaderOptions{
211212 -- indented code blocks
212213 , readerDefaultImageExtension :: String -- ^ Default extension for images
213214 , readerTrace :: Bool -- ^ Print debugging info
215+ , readerTrackChanges :: TrackChanges
214216} deriving (Show, Read)
215217
216218instance Default ReaderOptions
@@ -227,6 +229,7 @@ instance Default ReaderOptions
227229 , readerIndentedCodeClasses = []
228230 , readerDefaultImageExtension = ""
229231 , readerTrace = False
232+ , readerTrackChanges = AcceptChanges
230233 }
231234
232235--
@@ -264,6 +267,12 @@ data HTMLSlideVariant = S5Slides
264267 | NoSlides
265268 deriving (Show, Read, Eq)
266269
270+-- | Options for accepting or rejecting MS Word track-changes.
271+data TrackChanges = AcceptChanges
272+ | RejectChanges
273+ | AllChanges
274+ deriving (Show, Read, Eq)
275+
267276-- | Options for writers
268277data WriterOptions = WriterOptions
269278 { 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) =
234234
235235parPartToInlines :: ReaderOptions -> Docx -> ParPart -> [Inline]
236236parPartToInlines opts docx (PlainRun r) = runToInlines opts docx r
237−parPartToInlines opts docx (Insertion _ _ _ runs) =
238− concatMap (runToInlines opts docx) runs
239−parPartToInlines _ _ (Deletion _ _ _ _) = []
237+parPartToInlines opts docx (Insertion _ author date runs) =
238+ case readerTrackChanges opts of
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)]
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)]
240253parPartToInlines _ _ (BookMark _ anchor) | anchor `elem` dummyAnchors = []
241254parPartToInlines _ _ (BookMark _ anchor) = [Span (anchor, ["anchor"], []) []]
242255parPartToInlines _ (Docx _ _ _ rels _) (Drawing relid) =
tests/Tests/Readers/Docx.hs+28−4
@@ -124,13 +124,37 @@ tests = [ testGroup "inlines"
124124 ]
125125 , testGroup "track changes"
126126 [ testCompare
127− "insert insertion (insertions only)"
127+ "insertion (default)"
128128 "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"
130138 , 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)"
132156 "docx.track_changes_deletion.docx"
133− "docx.track_changes_deletion_only_ins.native"
157+ "docx.track_changes_deletion_all.native"
134158 ]
135159 ]
136160
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."]]