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:
parent
9570f59066
commit
ce1664cf2b
6 changed files with 49 additions and 62 deletions
74
MANUAL.txt
74
MANUAL.txt
|
@ -794,35 +794,20 @@ Options affecting specific writers
|
||||||
: Link to a CSS style sheet. This option can be used repeatedly to
|
: Link to a CSS style sheet. This option can be used repeatedly to
|
||||||
include multiple files. They will be included in the order specified.
|
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.
|
: Use the specified file as a style reference in producing a
|
||||||
For best results, the reference ODT should be a modified version
|
docx or ODT file.
|
||||||
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
|
Docx: For best results, the reference docx should be a modified
|
||||||
the default `reference.odt`: `pandoc
|
version of a docx file produced using pandoc. The contents
|
||||||
--print-default-data-file reference.odt >
|
of the reference docx are ignored, but its stylesheets and
|
||||||
custom-reference.odt`. Then open `custom-reference.docx` in
|
document properties (including margins, page size, header,
|
||||||
LibreOffice, modify the styles as you wish, and save the
|
and footer) are used in the new docx. If no reference docx
|
||||||
file.
|
is specified on the command line, pandoc will look for a
|
||||||
|
file `reference.docx` in the user data directory (see
|
||||||
`--reference-docx=`*FILE*
|
`--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 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.
|
|
||||||
|
|
||||||
To produce a custom `reference.docx`, first get a copy of
|
To produce a custom `reference.docx`, first get a copy of
|
||||||
the default `reference.docx`: `pandoc
|
the default `reference.docx`: `pandoc
|
||||||
|
@ -830,15 +815,30 @@ Options affecting specific writers
|
||||||
custom-reference.docx`. Then open `custom-reference.docx`
|
custom-reference.docx`. Then open `custom-reference.docx`
|
||||||
in Word, modify the styles as you wish, and save the file.
|
in Word, modify the styles as you wish, and save the file.
|
||||||
For best results, do not make changes to this file other
|
For best results, do not make changes to this file other
|
||||||
than modifying the styles used by pandoc: [paragraph] Normal,
|
than modifying the styles used by pandoc: [paragraph]
|
||||||
Body Text, First Paragraph, Compact, Title, Subtitle,
|
Normal, Body Text, First Paragraph, Compact, Title,
|
||||||
Author, Date, Abstract, Bibliography, Heading 1, Heading 2,
|
Subtitle, Author, Date, Abstract, Bibliography, Heading 1,
|
||||||
Heading 3, Heading 4, Heading 5, Heading 6, Block Text,
|
Heading 2, Heading 3, Heading 4, Heading 5, Heading 6, Block
|
||||||
Footnote Text, Definition Term, Definition, Caption, Table
|
Text, Footnote Text, Definition Term, Definition, Caption,
|
||||||
Caption, Image Caption, Figure, Figure With Caption, TOC
|
Table Caption, Image Caption, Figure, Figure With Caption,
|
||||||
Heading; [character] Default Paragraph Font, Body Text Char,
|
TOC Heading; [character] Default Paragraph Font, Body Text
|
||||||
Verbatim Char, Footnote Reference, Hyperlink; [table] Normal
|
Char, Verbatim Char, Footnote Reference, Hyperlink; [table]
|
||||||
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*
|
`--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.beamer` template, if you use `-t beamer`,
|
||||||
or the `default.context` template, if you use `-t context`).
|
or the `default.context` template, if you use `-t context`).
|
||||||
- `docx` has no template (however, you can use
|
- `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
|
Templates contain *variables*, which allow for the inclusion of
|
||||||
arbitrary information at any point in the file. Variables may be set
|
arbitrary information at any point in the file. Variables may be set
|
||||||
|
|
25
pandoc.hs
25
pandoc.hs
|
@ -185,8 +185,7 @@ data Opt = Opt
|
||||||
, optHighlightStyle :: Style -- ^ Style to use for highlighted code
|
, optHighlightStyle :: Style -- ^ Style to use for highlighted code
|
||||||
, optTopLevelDivision :: TopLevelDivision -- ^ Type of the top-level divisions
|
, optTopLevelDivision :: TopLevelDivision -- ^ Type of the top-level divisions
|
||||||
, optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
|
, optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
|
||||||
, optReferenceODT :: Maybe FilePath -- ^ Path of reference.odt
|
, optReferenceDoc :: Maybe FilePath -- ^ Path of reference doc
|
||||||
, optReferenceDocx :: Maybe FilePath -- ^ Path of reference.docx
|
|
||||||
, optEpubStylesheet :: Maybe String -- ^ EPUB stylesheet
|
, optEpubStylesheet :: Maybe String -- ^ EPUB stylesheet
|
||||||
, optEpubMetadata :: String -- ^ EPUB metadata
|
, optEpubMetadata :: String -- ^ EPUB metadata
|
||||||
, optEpubFonts :: [FilePath] -- ^ EPUB fonts to embed
|
, optEpubFonts :: [FilePath] -- ^ EPUB fonts to embed
|
||||||
|
@ -252,8 +251,7 @@ defaultOpts = Opt
|
||||||
, optHighlightStyle = pygments
|
, optHighlightStyle = pygments
|
||||||
, optTopLevelDivision = TopLevelDefault
|
, optTopLevelDivision = TopLevelDefault
|
||||||
, optHTMLMathMethod = PlainMath
|
, optHTMLMathMethod = PlainMath
|
||||||
, optReferenceODT = Nothing
|
, optReferenceDoc = Nothing
|
||||||
, optReferenceDocx = Nothing
|
|
||||||
, optEpubStylesheet = Nothing
|
, optEpubStylesheet = Nothing
|
||||||
, optEpubMetadata = ""
|
, optEpubMetadata = ""
|
||||||
, optEpubFonts = []
|
, optEpubFonts = []
|
||||||
|
@ -708,19 +706,12 @@ options =
|
||||||
"URL")
|
"URL")
|
||||||
"" -- "Link to CSS style sheet"
|
"" -- "Link to CSS style sheet"
|
||||||
|
|
||||||
, Option "" ["reference-odt"]
|
, Option "" ["reference-doc"]
|
||||||
(ReqArg
|
(ReqArg
|
||||||
(\arg opt ->
|
(\arg opt ->
|
||||||
return opt { optReferenceODT = Just arg })
|
return opt { optReferenceDoc = Just arg })
|
||||||
"FILENAME")
|
"FILENAME")
|
||||||
"" -- "Path of custom reference.odt"
|
"" -- "Path of custom reference doc"
|
||||||
|
|
||||||
, Option "" ["reference-docx"]
|
|
||||||
(ReqArg
|
|
||||||
(\arg opt ->
|
|
||||||
return opt { optReferenceDocx = Just arg })
|
|
||||||
"FILENAME")
|
|
||||||
"" -- "Path of custom reference.docx"
|
|
||||||
|
|
||||||
, Option "" ["epub-stylesheet"]
|
, Option "" ["epub-stylesheet"]
|
||||||
(ReqArg
|
(ReqArg
|
||||||
|
@ -1190,8 +1181,7 @@ convertWithOpts opts args = do
|
||||||
, optHighlightStyle = highlightStyle
|
, optHighlightStyle = highlightStyle
|
||||||
, optTopLevelDivision = topLevelDivision
|
, optTopLevelDivision = topLevelDivision
|
||||||
, optHTMLMathMethod = mathMethod'
|
, optHTMLMathMethod = mathMethod'
|
||||||
, optReferenceODT = referenceODT
|
, optReferenceDoc = referenceDoc
|
||||||
, optReferenceDocx = referenceDocx
|
|
||||||
, optEpubStylesheet = epubStylesheet
|
, optEpubStylesheet = epubStylesheet
|
||||||
, optEpubMetadata = epubMetadata
|
, optEpubMetadata = epubMetadata
|
||||||
, optEpubFonts = epubFonts
|
, optEpubFonts = epubFonts
|
||||||
|
@ -1485,8 +1475,7 @@ convertWithOpts opts args = do
|
||||||
writerEpubFonts = epubFonts,
|
writerEpubFonts = epubFonts,
|
||||||
writerEpubChapterLevel = epubChapterLevel,
|
writerEpubChapterLevel = epubChapterLevel,
|
||||||
writerTOCDepth = epubTOCDepth,
|
writerTOCDepth = epubTOCDepth,
|
||||||
writerReferenceODT = referenceODT,
|
writerReferenceDoc = referenceDoc,
|
||||||
writerReferenceDocx = referenceDocx,
|
|
||||||
writerMediaBag = media,
|
writerMediaBag = media,
|
||||||
writerVerbose = verbose,
|
writerVerbose = verbose,
|
||||||
writerLaTeXArgs = latexEngineArgs
|
writerLaTeXArgs = latexEngineArgs
|
||||||
|
|
|
@ -395,8 +395,7 @@ data WriterOptions = WriterOptions
|
||||||
, writerEpubFonts :: [FilePath] -- ^ Paths to fonts to embed
|
, writerEpubFonts :: [FilePath] -- ^ Paths to fonts to embed
|
||||||
, writerEpubChapterLevel :: Int -- ^ Header level for chapters (separate files)
|
, writerEpubChapterLevel :: Int -- ^ Header level for chapters (separate files)
|
||||||
, writerTOCDepth :: Int -- ^ Number of levels to include in TOC
|
, writerTOCDepth :: Int -- ^ Number of levels to include in TOC
|
||||||
, writerReferenceODT :: Maybe FilePath -- ^ Path to reference ODT if specified
|
, writerReferenceDoc :: Maybe FilePath -- ^ Path to reference document if specified
|
||||||
, writerReferenceDocx :: Maybe FilePath -- ^ Path to reference DOCX if specified
|
|
||||||
, writerMediaBag :: MediaBag -- ^ Media collected by docx or epub reader
|
, writerMediaBag :: MediaBag -- ^ Media collected by docx or epub reader
|
||||||
, writerVerbose :: Bool -- ^ Verbose debugging output
|
, writerVerbose :: Bool -- ^ Verbose debugging output
|
||||||
, writerLaTeXArgs :: [String] -- ^ Flags to pass to latex-engine
|
, writerLaTeXArgs :: [String] -- ^ Flags to pass to latex-engine
|
||||||
|
@ -442,8 +441,7 @@ instance Default WriterOptions where
|
||||||
, writerEpubFonts = []
|
, writerEpubFonts = []
|
||||||
, writerEpubChapterLevel = 1
|
, writerEpubChapterLevel = 1
|
||||||
, writerTOCDepth = 3
|
, writerTOCDepth = 3
|
||||||
, writerReferenceODT = Nothing
|
, writerReferenceDoc = Nothing
|
||||||
, writerReferenceDocx = Nothing
|
|
||||||
, writerMediaBag = mempty
|
, writerMediaBag = mempty
|
||||||
, writerVerbose = False
|
, writerVerbose = False
|
||||||
, writerLaTeXArgs = []
|
, writerLaTeXArgs = []
|
||||||
|
|
|
@ -225,7 +225,7 @@ writeDocx opts doc@(Pandoc meta _) = do
|
||||||
username <- P.lookupEnv "USERNAME"
|
username <- P.lookupEnv "USERNAME"
|
||||||
utctime <- P.getCurrentTime
|
utctime <- P.getCurrentTime
|
||||||
distArchive <- P.getDefaultReferenceDocx datadir
|
distArchive <- P.getDefaultReferenceDocx datadir
|
||||||
refArchive <- case writerReferenceDocx opts of
|
refArchive <- case writerReferenceDoc opts of
|
||||||
Just f -> toArchive <$> P.readFileLazy f
|
Just f -> toArchive <$> P.readFileLazy f
|
||||||
Nothing -> P.getDefaultReferenceDocx datadir
|
Nothing -> P.getDefaultReferenceDocx datadir
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ pandocToODT opts doc@(Pandoc meta _) = do
|
||||||
let datadir = writerUserDataDir opts
|
let datadir = writerUserDataDir opts
|
||||||
let title = docTitle meta
|
let title = docTitle meta
|
||||||
refArchive <-
|
refArchive <-
|
||||||
case writerReferenceODT opts of
|
case writerReferenceDoc opts of
|
||||||
Just f -> liftM toArchive $ lift $ P.readFileLazy f
|
Just f -> liftM toArchive $ lift $ P.readFileLazy f
|
||||||
Nothing -> lift $ P.getDefaultReferenceODT datadir
|
Nothing -> lift $ P.getDefaultReferenceODT datadir
|
||||||
-- handle formulas and pictures
|
-- handle formulas and pictures
|
||||||
|
|
|
@ -141,7 +141,7 @@ tests = [ testGroup "inlines"
|
||||||
]
|
]
|
||||||
, testGroup "customized styles"
|
, testGroup "customized styles"
|
||||||
[ testCompareWithOpts
|
[ testCompareWithOpts
|
||||||
( def{writerReferenceDocx=Just "docx/custom-style-reference.docx"}
|
( def{writerReferenceDoc=Just "docx/custom-style-reference.docx"}
|
||||||
, def)
|
, def)
|
||||||
"simple customized blocks and inlines"
|
"simple customized blocks and inlines"
|
||||||
"docx/custom-style-roundtrip-start.native"
|
"docx/custom-style-roundtrip-start.native"
|
||||||
|
|
Loading…
Reference in a new issue