aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers/HTML.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-08-14 22:11:05 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-08-25 14:24:31 -0700
commit1ee6e0e0878bcd655f31deb0caf6a4766e500cc6 (patch)
tree5f11cadde103d1cb72e9b1cbf6eeb2b61a570e9b /src/Text/Pandoc/Writers/HTML.hs
parent8959c44e6ae2a2f79ca55c2c173f84bf8d3abfc7 (diff)
downloadpandoc-1ee6e0e0878bcd655f31deb0caf6a4766e500cc6.tar.gz
Use new doctemplates, doclayout.
+ Remove Text.Pandoc.Pretty; use doclayout instead. [API change] + Text.Pandoc.Writers.Shared: remove metaToJSON, metaToJSON' [API change]. + Text.Pandoc.Writers.Shared: modify `addVariablesToContext`, `defField`, `setField`, `getField`, `resetField` to work with Context rather than JSON values. [API change] + Text.Pandoc.Writers.Shared: export new function `endsWithPlain` [API change]. + Use new templates and doclayout in writers. + Use Doc-based templates in all writers. + Adjust three tests for minor template rendering differences. + Added indentation to body in docbook4, docbook5 templates. The main impact of this change is better reflowing of content interpolated into templates. Previously, interpolated variables were rendered independently and intepolated as strings, which could lead to overly long lines. Now the templates interpolated as Doc values which may include breaking spaces, and reflowing occurs after template interpolation rather than before.
Diffstat (limited to 'src/Text/Pandoc/Writers/HTML.hs')
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index de1a98173..af0780e99 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -36,6 +36,7 @@ import Data.Maybe (catMaybes, fromMaybe, isJust, isNothing, mapMaybe)
import qualified Data.Set as Set
import Data.String (fromString)
import Data.Text (Text)
+import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import Network.HTTP (urlEncode)
import Network.URI (URI (..), parseURIReference)
@@ -53,7 +54,8 @@ import Text.Pandoc.ImageSize
import Text.Pandoc.Options
import Text.Pandoc.Shared
import Text.Pandoc.Slides
-import Text.Pandoc.Templates
+import Text.Pandoc.Templates (renderTemplate)
+import Text.DocTemplates (Context(..))
import Text.Pandoc.Walk
import Text.Pandoc.Writers.Math
import Text.Pandoc.Writers.Shared
@@ -71,7 +73,6 @@ import qualified Text.Blaze.Html5 as H5
import qualified Text.Blaze.Html5.Attributes as A5
#endif
import Control.Monad.Except (throwError)
-import Data.Aeson (Value)
import System.FilePath (takeBaseName)
import Text.Blaze.Html.Renderer.Text (renderHtml)
import qualified Text.Blaze.XHtml1.Transitional as H
@@ -215,17 +216,17 @@ writeHtmlString' st opts d = do
Nothing -> return $ renderHtml' body
Just tpl -> do
-- warn if empty lang
- when (isNothing (getField "lang" context :: Maybe String)) $
+ when (isNothing (getField "lang" context :: Maybe Text)) $
report NoLangSpecified
-- check for empty pagetitle
context' <-
case getField "pagetitle" context of
- Just (s :: String) | not (null s) -> return context
+ Just (s :: Text) | not (T.null s) -> return context
_ -> do
- let fallback = fromMaybe "Untitled" $ takeBaseName <$>
+ let fallback = maybe "Untitled" takeBaseName $
lookup "sourcefile" (writerVariables opts)
report $ NoTitleElement fallback
- return $ resetField "pagetitle" fallback context
+ return $ resetField "pagetitle" (T.pack fallback) context
return $ renderTemplate tpl
(defField "body" (renderHtml' body) context')
@@ -244,9 +245,9 @@ writeHtml' st opts d =
pandocToHtml :: PandocMonad m
=> WriterOptions
-> Pandoc
- -> StateT WriterState m (Html, Value)
+ -> StateT WriterState m (Html, Context Text)
pandocToHtml opts (Pandoc meta blocks) = do
- metadata <- metaToJSON opts
+ metadata <- metaToContext opts
(fmap renderHtml' . blockListToHtml opts)
(fmap renderHtml' . inlineListToHtml opts)
meta
@@ -298,7 +299,7 @@ pandocToHtml opts (Pandoc meta blocks) = do
let context = (if stHighlighting st
then case writerHighlightStyle opts of
Just sty -> defField "highlighting-css"
- (styleToCss sty)
+ (T.pack $ styleToCss sty)
Nothing -> id
else id) $
(if stMath st
@@ -307,7 +308,7 @@ pandocToHtml opts (Pandoc meta blocks) = do
(case writerHTMLMathMethod opts of
MathJax u -> defField "mathjax" True .
defField "mathjaxurl"
- (takeWhile (/='?') u)
+ (T.pack $ takeWhile (/='?') u)
_ -> defField "mathjax" False) $
defField "quotes" (stQuotes st) $
-- for backwards compatibility we populate toc
@@ -315,16 +316,18 @@ pandocToHtml opts (Pandoc meta blocks) = do
-- boolean:
maybe id (defField "toc") toc $
maybe id (defField "table-of-contents") toc $
- defField "author-meta" authsMeta $
- maybe id (defField "date-meta") (normalizeDate dateMeta) $
- defField "pagetitle" (stringifyHTML (docTitle meta)) $
- defField "idprefix" (writerIdentifierPrefix opts) $
+ defField "author-meta" (map T.pack authsMeta) $
+ maybe id (defField "date-meta" . T.pack)
+ (normalizeDate dateMeta) $
+ defField "pagetitle"
+ (T.pack . stringifyHTML . docTitle $ meta) $
+ defField "idprefix" (T.pack $ writerIdentifierPrefix opts) $
-- these should maybe be set in pandoc.hs
defField "slidy-url"
- ("https://www.w3.org/Talks/Tools/Slidy2" :: String) $
- defField "slideous-url" ("slideous" :: String) $
- defField "revealjs-url" ("reveal.js" :: String) $
- defField "s5-url" ("s5/default" :: String) $
+ ("https://www.w3.org/Talks/Tools/Slidy2" :: Text) $
+ defField "slideous-url" ("slideous" :: Text) $
+ defField "revealjs-url" ("reveal.js" :: Text) $
+ defField "s5-url" ("s5/default" :: Text) $
defField "html5" (stHtml5 st)
metadata
return (thebody, context)