aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README11
-rw-r--r--pandoc.hs17
-rw-r--r--src/Text/Pandoc/Options.hs9
-rw-r--r--src/Text/Pandoc/Readers/Docx.hs19
-rw-r--r--tests/Tests/Readers/Docx.hs32
-rw-r--r--tests/docx.track_changes_deletion_accept.native (renamed from tests/docx.track_changes_deletion_only_ins.native)0
-rw-r--r--tests/docx.track_changes_deletion_all.native1
-rw-r--r--tests/docx.track_changes_deletion_reject.native1
-rw-r--r--tests/docx.track_changes_insertion_accept.native (renamed from tests/docx.track_changes_insertion_only_ins.native)0
-rw-r--r--tests/docx.track_changes_insertion_all.native1
-rw-r--r--tests/docx.track_changes_insertion_reject.native1
11 files changed, 85 insertions, 7 deletions
diff --git a/README b/README
index 012b75e2a..80371e6f7 100644
--- a/README
+++ b/README
@@ -308,6 +308,17 @@ Reader options
`--tab-stop=`*NUMBER*
: Specify the number of spaces per tab (default is 4).
+`--track-changes=`*accept|reject|all*
+: Specifies what to do with insertions and deletions produced by the MS
+ Word "track-changes" feature. *accept* (the default), inserts all
+ insertions, and ignores all deletions. *reject* inserts all
+ deletions and ignores insertions. *all* puts in both insertions
+ and deletions, wrapped in spans with `insertion` and `deletion`
+ classes, respectively. The author and time of change is
+ included. *all* is useful for scripting: only accepting changes
+ from a certain reviewer, say, or before a certain date. This
+ option only affects the Docx reader.
+
General writer options
----------------------
diff --git a/pandoc.hs b/pandoc.hs
index 10673132b..588723322 100644
--- a/pandoc.hs
+++ b/pandoc.hs
@@ -174,6 +174,7 @@ data Opt = Opt
, optTeXLigatures :: Bool -- ^ Use TeX ligatures for quotes/dashes
, optDefaultImageExtension :: String -- ^ Default image extension
, optTrace :: Bool -- ^ Print debug information
+ , optTrackChanges :: TrackChanges -- ^ Accept or reject MS Word track-changes.
}
-- | Defaults for command-line options.
@@ -230,6 +231,7 @@ defaultOpts = Opt
, optTeXLigatures = True
, optDefaultImageExtension = ""
, optTrace = False
+ , optTrackChanges = AcceptChanges
}
-- | A list of functions, each transforming the options data structure
@@ -776,6 +778,19 @@ options =
(\opt -> return opt { optTrace = True }))
"" -- "Turn on diagnostic tracing in readers."
+ , Option "" ["track-changes"]
+ (ReqArg
+ (\arg opt -> do
+ action <- case arg of
+ "accept" -> return AcceptChanges
+ "reject" -> return RejectChanges
+ "all" -> return AllChanges
+ _ -> err 6
+ ("Unknown option for track-changes: " ++ arg)
+ return opt { optTrackChanges = action })
+ "accept|reject|all")
+ "" -- "Accepting or reject MS Word track-changes.""
+
, Option "" ["dump-args"]
(NoArg
(\opt -> return opt { optDumpArgs = True }))
@@ -973,6 +988,7 @@ main = do
, optTeXLigatures = texLigatures
, optDefaultImageExtension = defaultImageExtension
, optTrace = trace
+ , optTrackChanges = trackChanges
} = opts
when dumpArgs $
@@ -1097,6 +1113,7 @@ main = do
, readerApplyMacros = not laTeXOutput
, readerDefaultImageExtension = defaultImageExtension
, readerTrace = trace
+ , readerTrackChanges = trackChanges
}
let writerOptions = def { writerStandalone = standalone',
diff --git a/src/Text/Pandoc/Options.hs b/src/Text/Pandoc/Options.hs
index 611a6bb06..b7a3a4b7b 100644
--- a/src/Text/Pandoc/Options.hs
+++ b/src/Text/Pandoc/Options.hs
@@ -41,6 +41,7 @@ module Text.Pandoc.Options ( Extension(..)
, HTMLSlideVariant (..)
, EPUBVersion (..)
, WriterOptions (..)
+ , TrackChanges (..)
, def
, isEnabled
) where
@@ -211,6 +212,7 @@ data ReaderOptions = ReaderOptions{
-- indented code blocks
, readerDefaultImageExtension :: String -- ^ Default extension for images
, readerTrace :: Bool -- ^ Print debugging info
+ , readerTrackChanges :: TrackChanges
} deriving (Show, Read)
instance Default ReaderOptions
@@ -227,6 +229,7 @@ instance Default ReaderOptions
, readerIndentedCodeClasses = []
, readerDefaultImageExtension = ""
, readerTrace = False
+ , readerTrackChanges = AcceptChanges
}
--
@@ -264,6 +267,12 @@ data HTMLSlideVariant = S5Slides
| NoSlides
deriving (Show, Read, Eq)
+-- | Options for accepting or rejecting MS Word track-changes.
+data TrackChanges = AcceptChanges
+ | RejectChanges
+ | AllChanges
+ deriving (Show, Read, Eq)
+
-- | Options for writers
data WriterOptions = WriterOptions
{ writerStandalone :: Bool -- ^ Include header and footer
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs
index 130e2a1e2..cb0735e31 100644
--- a/src/Text/Pandoc/Readers/Docx.hs
+++ b/src/Text/Pandoc/Readers/Docx.hs
@@ -234,9 +234,22 @@ runToInlines opts docx@(Docx _ notes _ _ _) (Endnote fnId) =
parPartToInlines :: ReaderOptions -> Docx -> ParPart -> [Inline]
parPartToInlines opts docx (PlainRun r) = runToInlines opts docx r
-parPartToInlines opts docx (Insertion _ _ _ runs) =
- concatMap (runToInlines opts docx) runs
-parPartToInlines _ _ (Deletion _ _ _ _) = []
+parPartToInlines opts docx (Insertion _ author date runs) =
+ case readerTrackChanges opts of
+ AcceptChanges -> concatMap (runToInlines opts docx) runs
+ RejectChanges -> []
+ AllChanges ->
+ [Span
+ ("", ["insertion"], [("author", author), ("date", date)])
+ (concatMap (runToInlines opts docx) runs)]
+parPartToInlines opts docx (Deletion _ author date runs) =
+ case readerTrackChanges opts of
+ AcceptChanges -> []
+ RejectChanges -> concatMap (runToInlines opts docx) runs
+ AllChanges ->
+ [Span
+ ("", ["deletion"], [("author", author), ("date", date)])
+ (concatMap (runToInlines opts docx) runs)]
parPartToInlines _ _ (BookMark _ anchor) | anchor `elem` dummyAnchors = []
parPartToInlines _ _ (BookMark _ anchor) = [Span (anchor, ["anchor"], []) []]
parPartToInlines _ (Docx _ _ _ rels _) (Drawing relid) =
diff --git a/tests/Tests/Readers/Docx.hs b/tests/Tests/Readers/Docx.hs
index f34e123ed..8c51217cf 100644
--- a/tests/Tests/Readers/Docx.hs
+++ b/tests/Tests/Readers/Docx.hs
@@ -124,13 +124,37 @@ tests = [ testGroup "inlines"
]
, testGroup "track changes"
[ testCompare
- "insert insertion (insertions only)"
+ "insertion (default)"
"docx.track_changes_insertion.docx"
- "docx.track_changes_insertion_only_ins.native"
+ "docx.track_changes_insertion_accept.native"
+ , testCompareWithOpts def{readerTrackChanges=AcceptChanges}
+ "insert insertion (accept)"
+ "docx.track_changes_insertion.docx"
+ "docx.track_changes_insertion_accept.native"
+ , testCompareWithOpts def{readerTrackChanges=RejectChanges}
+ "remove insertion (reject)"
+ "docx.track_changes_insertion.docx"
+ "docx.track_changes_insertion_reject.native"
, testCompare
- "skip deletion (insertions only)"
+ "deletion (default)"
+ "docx.track_changes_deletion.docx"
+ "docx.track_changes_deletion_accept.native"
+ , testCompareWithOpts def{readerTrackChanges=AcceptChanges}
+ "remove deletion (accept)"
+ "docx.track_changes_deletion.docx"
+ "docx.track_changes_deletion_accept.native"
+ , testCompareWithOpts def{readerTrackChanges=RejectChanges}
+ "insert deletion (reject)"
+ "docx.track_changes_deletion.docx"
+ "docx.track_changes_deletion_reject.native"
+ , testCompareWithOpts def{readerTrackChanges=AllChanges}
+ "keep insertion (all)"
+ "docx.track_changes_deletion.docx"
+ "docx.track_changes_deletion_all.native"
+ , testCompareWithOpts def{readerTrackChanges=AllChanges}
+ "keep deletion (all)"
"docx.track_changes_deletion.docx"
- "docx.track_changes_deletion_only_ins.native"
+ "docx.track_changes_deletion_all.native"
]
]
diff --git a/tests/docx.track_changes_deletion_only_ins.native b/tests/docx.track_changes_deletion_accept.native
index 205c67810..205c67810 100644
--- a/tests/docx.track_changes_deletion_only_ins.native
+++ b/tests/docx.track_changes_deletion_accept.native
diff --git a/tests/docx.track_changes_deletion_all.native b/tests/docx.track_changes_deletion_all.native
new file mode 100644
index 000000000..7f4ed2a90
--- /dev/null
+++ b/tests/docx.track_changes_deletion_all.native
@@ -0,0 +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."]]
diff --git a/tests/docx.track_changes_deletion_reject.native b/tests/docx.track_changes_deletion_reject.native
new file mode 100644
index 000000000..04283bee5
--- /dev/null
+++ b/tests/docx.track_changes_deletion_reject.native
@@ -0,0 +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."]]
diff --git a/tests/docx.track_changes_insertion_only_ins.native b/tests/docx.track_changes_insertion_accept.native
index ca2e46df0..ca2e46df0 100644
--- a/tests/docx.track_changes_insertion_only_ins.native
+++ b/tests/docx.track_changes_insertion_accept.native
diff --git a/tests/docx.track_changes_insertion_all.native b/tests/docx.track_changes_insertion_all.native
new file mode 100644
index 000000000..12664e425
--- /dev/null
+++ b/tests/docx.track_changes_insertion_all.native
@@ -0,0 +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."]]
diff --git a/tests/docx.track_changes_insertion_reject.native b/tests/docx.track_changes_insertion_reject.native
new file mode 100644
index 000000000..def000abd
--- /dev/null
+++ b/tests/docx.track_changes_insertion_reject.native
@@ -0,0 +1 @@
+[Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "text",Space,Str "with",Space,Str "insertions."]]