diff options
author | John MacFarlane <jgm@berkeley.edu> | 2018-03-23 12:09:09 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2018-03-23 12:09:53 -0700 |
commit | db596a5b126520c311001010f573afe474dac1e5 (patch) | |
tree | 3ccd53e07672aa60bad55f703ded973cd506b4cd | |
parent | 435b1829b157685a2c055190703a4ee541f3bb12 (diff) | |
download | pandoc-db596a5b126520c311001010f573afe474dac1e5.tar.gz |
EPUB writer: ensure that pagetitle is always set...
even when structured titles are used.
This prevents spurious warnings about empty title elements.
Closes #4486.
-rw-r--r-- | src/Text/Pandoc/Writers/EPUB.hs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs index 8d0a46949..f1ff8b482 100644 --- a/src/Text/Pandoc/Writers/EPUB.hs +++ b/src/Text/Pandoc/Writers/EPUB.hs @@ -403,6 +403,12 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do writeHtmlStringForEPUB version o metadata <- getEPUBMetadata opts meta + let plainTitle = case docTitle' meta of + [] -> case epubTitle metadata of + [] -> "UNTITLED" + (x:_) -> titleText x + x -> stringify x + -- stylesheet stylesheets <- case epubStylesheets metadata of [] -> (\x -> [B.fromChunks [x]]) <$> @@ -440,6 +446,7 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do cpContent <- lift $ writeHtml opts'{ writerVariables = ("coverpage","true"): + ("pagetitle",plainTitle): cssvars True ++ vars } (Pandoc meta [RawBlock (Format "html") $ "<div id=\"cover-image\">\n<img src=\"../media/" ++ coverImage ++ "\" alt=\"cover image\" />\n</div>"]) imgContent <- lift $ P.readFileLazy img @@ -452,6 +459,7 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do -- title page tpContent <- lift $ writeHtml opts'{ writerVariables = ("titlepage","true"): + ("pagetitle",plainTitle): cssvars True ++ vars } (Pandoc meta []) tpEntry <- mkEntry "text/title_page.xhtml" tpContent @@ -604,11 +612,6 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do $ eRelativePath ent), ("media-type", fromMaybe "" $ getMimeType $ eRelativePath ent)] $ () - let plainTitle = case docTitle' meta of - [] -> case epubTitle metadata of - [] -> "UNTITLED" - (x:_) -> titleText x - x -> stringify x let tocTitle = fromMaybe plainTitle $ metaValueToString <$> lookupMeta "toc-title" meta @@ -749,7 +752,10 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do where titElements = parseXML titRendered titRendered = case P.runPure (writeHtmlStringForEPUB version - opts{ writerTemplate = Nothing } + opts{ writerTemplate = Nothing + , writerVariables = + ("pagetitle",plainTitle): + writerVariables opts} (Pandoc nullMeta [Plain $ walk clean tit])) of Left _ -> TS.pack $ stringify tit |