aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2022-12-04 09:56:54 -0800
committerJohn MacFarlane <[email protected]>2022-12-04 09:59:05 -0800
commitaaa3beacc0c624fc3bd3ac154024a6be36af83af (patch)
tree667cae7ef80ee85af72611a9ec181a8c45464fe9
parentb34ec00607c0218b3f9e8718d0fc68b3cf228f6c (diff)
EPUB writer: make title page optional.
New command line option: `--epub-title-page=true|false`. New `writerEpubTitlePage` field on `WriterOptions` [API change]. New `optEpubTitlePage` field on `Opts` [API change]. Closes #6097.
-rw-r--r--MANUAL.txt9
-rw-r--r--src/Text/Pandoc/App/CommandLineOptions.hs12
-rw-r--r--src/Text/Pandoc/App/Opt.hs3
-rw-r--r--src/Text/Pandoc/App/OutputSettings.hs1
-rw-r--r--src/Text/Pandoc/Options.hs2
-rw-r--r--src/Text/Pandoc/Writers/EPUB.hs22
6 files changed, 39 insertions, 10 deletions
diff --git a/MANUAL.txt b/MANUAL.txt
index 9b7d16170..01e37846c 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -1250,6 +1250,11 @@ header when requesting a document from a URL:
in a Markdown source document you can also specify `cover-image`
in a YAML metadata block (see [EPUB Metadata], below).
+`--epub-title-page=true`|`false`
+
+: Determines whether a the title page is included in the EPUB
+ (default is `true`).
+
`--epub-metadata=`*FILE*
: Look in the specified XML file for metadata for the EPUB.
@@ -1956,6 +1961,10 @@ To include the built-in citeproc filter, use either `citeproc` or
| ``` | ``` |
+----------------------------------+-----------------------------------+
| ``` | ``` yaml |
+| --epub-title-page=false | epub-title-page: false |
+| ``` | ``` |
++----------------------------------+-----------------------------------+
+| ``` | ``` yaml |
| --epub-metadata meta.xml | epub-metadata: meta.xml |
| ``` | ``` |
+----------------------------------+-----------------------------------+
diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs
index 4e581e187..78f548fb3 100644
--- a/src/Text/Pandoc/App/CommandLineOptions.hs
+++ b/src/Text/Pandoc/App/CommandLineOptions.hs
@@ -745,6 +745,18 @@ options =
"FILE")
"" -- "Path of epub cover image"
+ , Option "" ["epub-title-page"]
+ (ReqArg
+ (\arg opt ->
+ case arg of
+ "true" -> return opt{ optEpubTitlePage = True }
+ "false" -> return opt{ optEpubTitlePage = False }
+ _ -> optError $ PandocOptionError $
+ "Argument to --epub-title-page must be " <>
+ "true or false" )
+ "true|false")
+ ""
+
, Option "" ["epub-metadata"]
(ReqArg
(\arg opt -> return opt { optEpubMetadata = Just $
diff --git a/src/Text/Pandoc/App/Opt.hs b/src/Text/Pandoc/App/Opt.hs
index a8b08e7a8..80864967f 100644
--- a/src/Text/Pandoc/App/Opt.hs
+++ b/src/Text/Pandoc/App/Opt.hs
@@ -131,6 +131,7 @@ data Opt = Opt
, optEpubFonts :: [FilePath] -- ^ EPUB fonts to embed
, optEpubChapterLevel :: Int -- ^ Header level at which to split chapters
, optEpubCoverImage :: Maybe FilePath -- ^ Cover image for epub
+ , optEpubTitlePage :: Bool -- ^ INclude title page in EPUB
, optTOCDepth :: Int -- ^ Number of levels to include in TOC
, optDumpArgs :: Bool -- ^ Output command-line arguments
, optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
@@ -211,6 +212,7 @@ instance FromJSON Opt where
<*> o .:? "epub-fonts" .!= optEpubFonts defaultOpts
<*> o .:? "epub-chapter-level" .!= optEpubChapterLevel defaultOpts
<*> o .:? "epub-cover-image"
+ <*> o .:? "epub-title-page" .!= optEpubTitlePage defaultOpts
<*> o .:? "toc-depth" .!= optTOCDepth defaultOpts
<*> o .:? "dump-args" .!= optDumpArgs defaultOpts
<*> o .:? "ignore-args" .!= optIgnoreArgs defaultOpts
@@ -739,6 +741,7 @@ defaultOpts = Opt
, optEpubFonts = []
, optEpubChapterLevel = 1
, optEpubCoverImage = Nothing
+ , optEpubTitlePage = True
, optTOCDepth = 3
, optDumpArgs = False
, optIgnoreArgs = False
diff --git a/src/Text/Pandoc/App/OutputSettings.hs b/src/Text/Pandoc/App/OutputSettings.hs
index 56020cd1f..8b5d450cf 100644
--- a/src/Text/Pandoc/App/OutputSettings.hs
+++ b/src/Text/Pandoc/App/OutputSettings.hs
@@ -239,6 +239,7 @@ optToOutputSettings scriptingEngine opts = do
, writerEpubMetadata = epubMetadata
, writerEpubFonts = optEpubFonts opts
, writerEpubChapterLevel = optEpubChapterLevel opts
+ , writerEpubTitlePage = optEpubTitlePage opts
, writerTOCDepth = optTOCDepth opts
, writerReferenceDoc = optReferenceDoc opts
, writerSyntaxMap = syntaxMap
diff --git a/src/Text/Pandoc/Options.hs b/src/Text/Pandoc/Options.hs
index d7040a97c..f466d4480 100644
--- a/src/Text/Pandoc/Options.hs
+++ b/src/Text/Pandoc/Options.hs
@@ -317,6 +317,7 @@ data WriterOptions = WriterOptions
, writerEpubMetadata :: Maybe Text -- ^ Metadata to include in EPUB
, writerEpubFonts :: [FilePath] -- ^ Paths to fonts to embed
, writerEpubChapterLevel :: Int -- ^ Header level for chapters (separate files)
+ , writerEpubTitlePage :: Bool -- ^ Include title page in epub
, writerTOCDepth :: Int -- ^ Number of levels to include in TOC
, writerReferenceDoc :: Maybe FilePath -- ^ Path to reference document if specified
, writerReferenceLocation :: ReferenceLocation -- ^ Location of footnotes and references for writing markdown
@@ -353,6 +354,7 @@ instance Default WriterOptions where
, writerEpubMetadata = Nothing
, writerEpubFonts = []
, writerEpubChapterLevel = 1
+ , writerEpubTitlePage = True
, writerTOCDepth = 3
, writerReferenceDoc = Nothing
, writerReferenceLocation = EndOfDocument
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs
index 5b2797c4a..358318ef6 100644
--- a/src/Text/Pandoc/Writers/EPUB.hs
+++ b/src/Text/Pandoc/Writers/EPUB.hs
@@ -633,7 +633,9 @@ pandocToEPUB version opts doc = do
(n :: Int, fp) <- zip [1..] (map
(makeRelative epubSubdir . eRelativePath)
stylesheetEntries) ] ++
- map chapterNode (cpgEntry ++ (tpEntry : chapterEntries)) ++
+ map chapterNode (cpgEntry ++
+ [tpEntry | writerEpubTitlePage opts] ++
+ chapterEntries) ++
(case cpicEntry of
[] -> []
(x:_) -> [add_attrs
@@ -647,11 +649,12 @@ pandocToEPUB version opts doc = do
Nothing -> []
Just _ -> [ unode "itemref" !
[("idref", "cover_xhtml")] $ () ]
- ++ ((unode "itemref" ! [("idref", "title_page_xhtml")
+ ++ ([unode "itemref" ! [("idref", "title_page_xhtml")
,("linear",
case lookupMeta "title" meta of
Just _ -> "yes"
- Nothing -> "no")] $ ()) :
+ Nothing -> "no")] $ ()
+ | writerEpubTitlePage opts] ++
[unode "itemref" ! [("idref", "nav")] $ ()
| writerTableOfContents opts ] ++
map chapterRefNode chapterEntries)
@@ -677,7 +680,7 @@ pandocToEPUB version opts doc = do
-- Create the navEntry using the metadata, all of the various writer options,
-- the CSS and HTML helpers, the document and toc title as well as the epub version and all of the sections
- navEntry <- createNavEntry opts' meta metadata True vars cssvars
+ navEntry <- createNavEntry opts' meta metadata vars cssvars
writeHtml tocTitle version (chunkedTOC chunkedDoc)
-- mimetype
@@ -706,7 +709,8 @@ pandocToEPUB version opts doc = do
-- construct archive
let archive = foldr addEntryToArchive emptyArchive $
[mimetypeEntry, containerEntry, appleEntry,
- contentsEntry, tocEntry, navEntry, tpEntry] ++
+ contentsEntry, tocEntry, navEntry] ++
+ [tpEntry | writerEpubTitlePage opts] ++
stylesheetEntries ++ picEntries ++ cpicEntry ++
cpgEntry ++ chapterEntries ++ fontEntries
return $ fromArchive archive
@@ -870,8 +874,7 @@ createTocEntry opts meta metadata plainTitle (Node _ secs) = do
Just img -> [unode "meta" ! [("name","cover"),
("content", toId img)] $ ()]
, unode "docTitle" $ unode "text" plainTitle
- , unode "navMap" $
- tpNode : navMap
+ , unode "navMap" $ [tpNode | writerEpubTitlePage opts] ++ navMap
]
mkEntry "toc.ncx" tocData
@@ -880,7 +883,6 @@ createNavEntry :: PandocMonad m
=> WriterOptions
-> Meta
-> EPUBMetadata
- -> Bool
-> Context Text
-> (Bool -> Context Text)
-> (WriterOptions -> Pandoc -> m B8.ByteString)
@@ -888,7 +890,7 @@ createNavEntry :: PandocMonad m
-> EPUBVersion
-> Tree SecInfo
-> StateT EPUBState m Entry
-createNavEntry opts meta metadata includeTitlePage
+createNavEntry opts meta metadata
vars cssvars writeHtml tocTitle version (Node _ secs) = do
let mkItem :: Tree SecInfo -> State Int (Maybe Element)
mkItem (Node secinfo subsecs)
@@ -940,7 +942,7 @@ createNavEntry opts meta metadata includeTitlePage
"text/title_page.xhtml")
,("epub:type", "titlepage")] $
("Title Page" :: Text) ] |
- includeTitlePage ] ++
+ writerEpubTitlePage opts ] ++
[ unode "li"
[ unode "a" ! [("href", "text/cover.xhtml")
,("epub:type", "cover")] $