Simplified reference-docx/reference-odt to reference-doc.

* Text.Pandoc.Options.WriterOptions: removed writerReferenceDocx
  and writerReferenceODT, replaced them with writerReferenceDoc.
  This can hold either an ODT or a Docx. In this way, writerReferenceDoc
  is like writerTemplate, which can hold templates of different
  formats. [API change]

* Removed `--reference-docx` and `--reference-odt` options.

* Added `--reference-doc` option.
This commit is contained in:
John MacFarlane 2016-12-10 10:39:44 +01:00
parent 9570f59066
commit ce1664cf2b
6 changed files with 49 additions and 62 deletions

View file

@ -794,35 +794,20 @@ Options affecting specific writers
: Link to a CSS style sheet. This option can be used repeatedly to
include multiple files. They will be included in the order specified.
`--reference-odt=`*FILE*
`--reference-doc=`*FILE*
: Use the specified file as a style reference in producing an ODT.
For best results, the reference ODT should be a modified version
of an ODT produced using pandoc. The contents of the reference ODT
are ignored, but its stylesheets are used in the new ODT. If no
reference ODT is specified on the command line, pandoc will look
for a file `reference.odt` in the user data directory (see
`--data-dir`). If this is not found either, sensible defaults will be
used.
: Use the specified file as a style reference in producing a
docx or ODT file.
To produce a custom `reference.odt`, first get a copy of
the default `reference.odt`: `pandoc
--print-default-data-file reference.odt >
custom-reference.odt`. Then open `custom-reference.docx` in
LibreOffice, modify the styles as you wish, and save the
file.
`--reference-docx=`*FILE*
: Use the specified file as a style reference in producing a docx file.
For best results, the reference docx should be a modified version
of a docx file produced using pandoc. The contents of the reference docx
are ignored, but its stylesheets and document properties (including
margins, page size, header, and footer) are used in the new docx. If no
reference docx is specified on the command line, pandoc will look
for a file `reference.docx` in the user data directory (see
`--data-dir`). If this is not found either, sensible defaults will be
used.
Docx: For best results, the reference docx should be a modified
version of a docx file produced using pandoc. The contents
of the reference docx are ignored, but its stylesheets and
document properties (including margins, page size, header,
and footer) are used in the new docx. If no reference docx
is specified on the command line, pandoc will look for a
file `reference.docx` in the user data directory (see
`--data-dir`). If this is not found either, sensible
defaults will be used.
To produce a custom `reference.docx`, first get a copy of
the default `reference.docx`: `pandoc
@ -830,15 +815,30 @@ Options affecting specific writers
custom-reference.docx`. Then open `custom-reference.docx`
in Word, modify the styles as you wish, and save the file.
For best results, do not make changes to this file other
than modifying the styles used by pandoc: [paragraph] Normal,
Body Text, First Paragraph, Compact, Title, Subtitle,
Author, Date, Abstract, Bibliography, Heading 1, Heading 2,
Heading 3, Heading 4, Heading 5, Heading 6, Block Text,
Footnote Text, Definition Term, Definition, Caption, Table
Caption, Image Caption, Figure, Figure With Caption, TOC
Heading; [character] Default Paragraph Font, Body Text Char,
Verbatim Char, Footnote Reference, Hyperlink; [table] Normal
Table.
than modifying the styles used by pandoc: [paragraph]
Normal, Body Text, First Paragraph, Compact, Title,
Subtitle, Author, Date, Abstract, Bibliography, Heading 1,
Heading 2, Heading 3, Heading 4, Heading 5, Heading 6, Block
Text, Footnote Text, Definition Term, Definition, Caption,
Table Caption, Image Caption, Figure, Figure With Caption,
TOC Heading; [character] Default Paragraph Font, Body Text
Char, Verbatim Char, Footnote Reference, Hyperlink; [table]
Normal Table.
ODT: For best results, the reference ODT should be a modified
version of an ODT produced using pandoc. The contents of
the reference ODT are ignored, but its stylesheets are used
in the new ODT. If no reference ODT is specified on the
command line, pandoc will look for a file `reference.odt` in
the user data directory (see `--data-dir`). If this is not
found either, sensible defaults will be used.
To produce a custom `reference.odt`, first get a copy of
the default `reference.odt`: `pandoc
--print-default-data-file reference.odt >
custom-reference.odt`. Then open `custom-reference.docx` in
LibreOffice, modify the styles as you wish, and save the
file.
`--epub-stylesheet=`*FILE*
@ -1099,7 +1099,7 @@ directory (see `--data-dir`, above). *Exceptions:*
(or the `default.beamer` template, if you use `-t beamer`,
or the `default.context` template, if you use `-t context`).
- `docx` has no template (however, you can use
`--reference-docx` to customize the output).
`--reference-doc` to customize the output).
Templates contain *variables*, which allow for the inclusion of
arbitrary information at any point in the file. Variables may be set

View file

@ -185,8 +185,7 @@ data Opt = Opt
, optHighlightStyle :: Style -- ^ Style to use for highlighted code
, optTopLevelDivision :: TopLevelDivision -- ^ Type of the top-level divisions
, optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
, optReferenceODT :: Maybe FilePath -- ^ Path of reference.odt
, optReferenceDocx :: Maybe FilePath -- ^ Path of reference.docx
, optReferenceDoc :: Maybe FilePath -- ^ Path of reference doc
, optEpubStylesheet :: Maybe String -- ^ EPUB stylesheet
, optEpubMetadata :: String -- ^ EPUB metadata
, optEpubFonts :: [FilePath] -- ^ EPUB fonts to embed
@ -252,8 +251,7 @@ defaultOpts = Opt
, optHighlightStyle = pygments
, optTopLevelDivision = TopLevelDefault
, optHTMLMathMethod = PlainMath
, optReferenceODT = Nothing
, optReferenceDocx = Nothing
, optReferenceDoc = Nothing
, optEpubStylesheet = Nothing
, optEpubMetadata = ""
, optEpubFonts = []
@ -708,19 +706,12 @@ options =
"URL")
"" -- "Link to CSS style sheet"
, Option "" ["reference-odt"]
, Option "" ["reference-doc"]
(ReqArg
(\arg opt ->
return opt { optReferenceODT = Just arg })
return opt { optReferenceDoc = Just arg })
"FILENAME")
"" -- "Path of custom reference.odt"
, Option "" ["reference-docx"]
(ReqArg
(\arg opt ->
return opt { optReferenceDocx = Just arg })
"FILENAME")
"" -- "Path of custom reference.docx"
"" -- "Path of custom reference doc"
, Option "" ["epub-stylesheet"]
(ReqArg
@ -1190,8 +1181,7 @@ convertWithOpts opts args = do
, optHighlightStyle = highlightStyle
, optTopLevelDivision = topLevelDivision
, optHTMLMathMethod = mathMethod'
, optReferenceODT = referenceODT
, optReferenceDocx = referenceDocx
, optReferenceDoc = referenceDoc
, optEpubStylesheet = epubStylesheet
, optEpubMetadata = epubMetadata
, optEpubFonts = epubFonts
@ -1485,8 +1475,7 @@ convertWithOpts opts args = do
writerEpubFonts = epubFonts,
writerEpubChapterLevel = epubChapterLevel,
writerTOCDepth = epubTOCDepth,
writerReferenceODT = referenceODT,
writerReferenceDocx = referenceDocx,
writerReferenceDoc = referenceDoc,
writerMediaBag = media,
writerVerbose = verbose,
writerLaTeXArgs = latexEngineArgs

View file

@ -395,8 +395,7 @@ data WriterOptions = WriterOptions
, writerEpubFonts :: [FilePath] -- ^ Paths to fonts to embed
, writerEpubChapterLevel :: Int -- ^ Header level for chapters (separate files)
, writerTOCDepth :: Int -- ^ Number of levels to include in TOC
, writerReferenceODT :: Maybe FilePath -- ^ Path to reference ODT if specified
, writerReferenceDocx :: Maybe FilePath -- ^ Path to reference DOCX if specified
, writerReferenceDoc :: Maybe FilePath -- ^ Path to reference document if specified
, writerMediaBag :: MediaBag -- ^ Media collected by docx or epub reader
, writerVerbose :: Bool -- ^ Verbose debugging output
, writerLaTeXArgs :: [String] -- ^ Flags to pass to latex-engine
@ -442,8 +441,7 @@ instance Default WriterOptions where
, writerEpubFonts = []
, writerEpubChapterLevel = 1
, writerTOCDepth = 3
, writerReferenceODT = Nothing
, writerReferenceDocx = Nothing
, writerReferenceDoc = Nothing
, writerMediaBag = mempty
, writerVerbose = False
, writerLaTeXArgs = []

View file

@ -225,7 +225,7 @@ writeDocx opts doc@(Pandoc meta _) = do
username <- P.lookupEnv "USERNAME"
utctime <- P.getCurrentTime
distArchive <- P.getDefaultReferenceDocx datadir
refArchive <- case writerReferenceDocx opts of
refArchive <- case writerReferenceDoc opts of
Just f -> toArchive <$> P.readFileLazy f
Nothing -> P.getDefaultReferenceDocx datadir

View file

@ -77,7 +77,7 @@ pandocToODT opts doc@(Pandoc meta _) = do
let datadir = writerUserDataDir opts
let title = docTitle meta
refArchive <-
case writerReferenceODT opts of
case writerReferenceDoc opts of
Just f -> liftM toArchive $ lift $ P.readFileLazy f
Nothing -> lift $ P.getDefaultReferenceODT datadir
-- handle formulas and pictures

View file

@ -141,7 +141,7 @@ tests = [ testGroup "inlines"
]
, testGroup "customized styles"
[ testCompareWithOpts
( def{writerReferenceDocx=Just "docx/custom-style-reference.docx"}
( def{writerReferenceDoc=Just "docx/custom-style-reference.docx"}
, def)
"simple customized blocks and inlines"
"docx/custom-style-roundtrip-start.native"