From 69b3a369cacdae089d78dfb2e78287176f81a111 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 4 Mar 2017 11:14:10 +0100 Subject: HTML writer: issue warning if no title specified and template used. See #3473. --- src/Text/Pandoc/Writers/HTML.hs | 21 ++++++++++++++------- test/lhs-test.html | 2 +- test/lhs-test.html+lhs | 2 +- 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 @@ - + Untitled