summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-03-04 11:14:10 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-03-04 11:14:41 +0100
commit69b3a369cacdae089d78dfb2e78287176f81a111 (patch)
tree7b1457a50dcc8ddb7defd3c4758992a08274c030
parent87764b1c46b68de556698bad797fd46dedd4dc96 (diff)
HTML writer: issue warning if no title specified and template used.
See #3473.
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs21
-rw-r--r--test/lhs-test.html2
-rw-r--r--test/lhs-test.html+lhs2
3 files changed, 16 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index 2afd84598..332536492 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -186,18 +186,25 @@ writeHtmlString' :: PandocMonad m
=> WriterState -> WriterOptions -> Pandoc -> m String
writeHtmlString' st opts d = do
(body, context) <- evalStateT (pandocToHtml opts d) st
+ -- check for empty pagetitle
+ context' <-
+ case getField "pagetitle" context of
+ Just (s :: String) | not (null s) -> return context
+ _ -> do
+ report $ NoTitleElement "Untitled"
+ return $ resetField "pagetitle" ("Untitled" :: String) context
return $ case writerTemplate opts of
Nothing -> renderHtml body
Just tpl -> renderTemplate' tpl $
- defField "body" (renderHtml body) context
+ defField "body" (renderHtml body) context'
writeHtml' :: PandocMonad m => WriterState -> WriterOptions -> Pandoc -> m Html
writeHtml' st opts d = do
- (body, context) <- evalStateT (pandocToHtml opts d) st
- return $ case writerTemplate opts of
- Nothing -> body
- Just tpl -> renderTemplate' tpl $
- defField "body" (renderHtml body) context
+ case writerTemplate opts of
+ Just _ -> preEscapedString <$> writeHtmlString' st opts d
+ Nothing -> do
+ (body, _) <- evalStateT (pandocToHtml opts d) st
+ return body
-- result is (title, authors, date, toc, body, new variables)
pandocToHtml :: PandocMonad m
@@ -267,7 +274,7 @@ pandocToHtml opts (Pandoc meta blocks) = do
maybe id (defField "toc" . renderHtml) toc $
defField "author-meta" authsMeta $
maybe id (defField "date-meta") (normalizeDate dateMeta) $
- defField "pagetitle" (stringifyHTML $ docTitle meta) $
+ defField "pagetitle" (stringifyHTML (docTitle meta)) $
defField "idprefix" (writerIdentifierPrefix opts) $
-- these should maybe be set in pandoc.hs
defField "slidy-url"
diff --git a/test/lhs-test.html b/test/lhs-test.html
index 759b0955b..0ee25be30 100644
--- a/test/lhs-test.html
+++ b/test/lhs-test.html
@@ -4,7 +4,7 @@
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
- <title></title>
+ <title>Untitled</title>
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
div.sourceCode { overflow-x: auto; }
diff --git a/test/lhs-test.html+lhs b/test/lhs-test.html+lhs
index 5fed70ddc..10778e239 100644
--- a/test/lhs-test.html+lhs
+++ b/test/lhs-test.html+lhs
@@ -4,7 +4,7 @@
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
- <title></title>
+ <title>Untitled</title>
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
div.sourceCode { overflow-x: auto; }