git.iko.soy/typeable/pandoc
on master help sign in
HTML writer: fallback to basename rather than Untitled.
commit239a17a9863db9eea87e142931e6647b0e0064e1 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 9 Mar 2017, 09:41 (10 years ago) parentfd35661
3 files changed+7−6
src/Text/Pandoc/Writers/HTML.hs+5−4 test/lhs-test.html+1−1 test/lhs-test.html+lhs+1−1
src/Text/Pandoc/Writers/HTML.hs+5−4
@@ -76,7 +76,7 @@ import qualified Text.Blaze.Html5 as H5
7676#endif
7777import Control.Monad.Except (throwError)
7878import Data.Aeson (Value)
79−import System.FilePath (takeExtension)
79+import System.FilePath (takeExtension, takeBaseName)
8080import Text.Blaze.Html.Renderer.String (renderHtml)
8181import qualified Text.Blaze.XHtml1.Transitional as H
8282import qualified Text.Blaze.XHtml1.Transitional.Attributes as A
@@ -197,9 +197,10 @@ writeHtmlString' st opts d = do
197197 case getField "pagetitle" context of
198198 Just (s :: String) | not (null s) -> return context
199199 _ -> do
200− report $ NoTitleElement "Untitled"
201− return $ resetField "pagetitle" ("Untitled" :: String)
202− context
200+ let fallback = fromMaybe "Untitled" $ takeBaseName <$>
201+ lookup "sourcefile" (writerVariables opts)
202+ report $ NoTitleElement fallback
203+ return $ resetField "pagetitle" fallback context
203204 return $ renderTemplate' tpl $
204205 defField "body" (renderHtml body) context'
205206
test/lhs-test.html+1−1
@@ -4,7 +4,7 @@
44 <meta charset="utf-8" />
55 <meta name="generator" content="pandoc" />
66 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
7− <title>Untitled</title>
7+ <title>lhs-test</title>
88 <style type="text/css">
99 code{white-space: pre-wrap;}
1010 .smallcaps{font-variant: small-caps;}
test/lhs-test.html+lhs+1−1
@@ -4,7 +4,7 @@
44 <meta charset="utf-8" />
55 <meta name="generator" content="pandoc" />
66 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
7− <title>Untitled</title>
7+ <title>lhs-test</title>
88 <style type="text/css">
99 code{white-space: pre-wrap;}
1010 .smallcaps{font-variant: small-caps;}