From 239a17a9863db9eea87e142931e6647b0e0064e1 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 9 Mar 2017 09:41:22 +0100 Subject: HTML writer: fallback to basename rather than Untitled. --- src/Text/Pandoc/Writers/HTML.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index e904b5fb7..ab2713748 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -76,7 +76,7 @@ import qualified Text.Blaze.Html5 as H5 #endif import Control.Monad.Except (throwError) import Data.Aeson (Value) -import System.FilePath (takeExtension) +import System.FilePath (takeExtension, takeBaseName) import Text.Blaze.Html.Renderer.String (renderHtml) import qualified Text.Blaze.XHtml1.Transitional as H import qualified Text.Blaze.XHtml1.Transitional.Attributes as A @@ -197,9 +197,10 @@ writeHtmlString' st opts d = do case getField "pagetitle" context of Just (s :: String) | not (null s) -> return context _ -> do - report $ NoTitleElement "Untitled" - return $ resetField "pagetitle" ("Untitled" :: String) - context + let fallback = fromMaybe "Untitled" $ takeBaseName <$> + lookup "sourcefile" (writerVariables opts) + report $ NoTitleElement fallback + return $ resetField "pagetitle" fallback context return $ renderTemplate' tpl $ defField "body" (renderHtml body) context' -- cgit v1.2.3