aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-03-09 09:41:22 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-03-09 09:41:22 +0100
commit239a17a9863db9eea87e142931e6647b0e0064e1 (patch)
tree6100bdbaad97d07cb98b7bcb8f0f0850ce60d0af /src/Text
parentfd35661646b87c4960f6c610de06c891c78e9aab (diff)
downloadpandoc-239a17a9863db9eea87e142931e6647b0e0064e1.tar.gz
HTML writer: fallback to basename rather than Untitled.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs9
1 files changed, 5 insertions, 4 deletions
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'