summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-05-16 23:00:58 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-06-24 20:27:37 -0700
commite32a8f5981969bb6d0a11bd945188c35817e4d96 (patch)
tree83b5db93df221f960f9b32387147cc692ef10103 /src/Text/Pandoc/Writers
parent5f4a32e46588b5a89cfa38d7ac51e192d62430cc (diff)
Revised Text.Pandoc.Templates to accept JSON contexts.
Currently the library is set up with a shim for association lists, for compatibility, but this can change when the writers are changed. New export: `varListToJSON`. Removed `Empty`. Simplified template type to a newtype.
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs6
-rw-r--r--src/Text/Pandoc/Writers/Man.hs6
2 files changed, 10 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index 1e4b19184..1cc17d7fd 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -45,6 +45,7 @@ import Numeric ( showHex )
import Data.Char ( ord, toLower )
import Data.List ( isPrefixOf, intersperse )
import Data.String ( fromString )
+import qualified Data.Text as T
import Data.Maybe ( catMaybes )
import Control.Monad.State
import Text.Blaze.Html hiding(contents)
@@ -212,7 +213,10 @@ inTemplate opts tit auths authsMeta date toc body' newvars =
Nothing -> []) ++
[ ("author", renderHtml a) | a <- auths ] ++
[ ("author-meta", stripTags $ renderHtml a) | a <- authsMeta ]
- in renderTemplate context $ writerTemplate opts
+ template = case compileTemplate (T.pack $ writerTemplate opts) of
+ Left e -> error e
+ Right t -> t
+ in renderTemplate template (varListToJSON context)
-- | Like Text.XHtml's identifier, but adds the writerIdentifierPrefix
prefixedId :: WriterOptions -> String -> Attribute
diff --git a/src/Text/Pandoc/Writers/Man.hs b/src/Text/Pandoc/Writers/Man.hs
index 5541aeb3b..17be983ce 100644
--- a/src/Text/Pandoc/Writers/Man.hs
+++ b/src/Text/Pandoc/Writers/Man.hs
@@ -38,6 +38,7 @@ import Text.Printf ( printf )
import Data.List ( isPrefixOf, intersperse, intercalate )
import Text.Pandoc.Pretty
import Control.Monad.State
+import qualified Data.Text as T
type Notes = [[Block]]
data WriterState = WriterState { stNotes :: Notes
@@ -77,8 +78,11 @@ pandocToMan opts (Pandoc (Meta title authors date) blocks) = do
, ("description", render' description) ] ++
[ ("has-tables", "yes") | hasTables ] ++
[ ("author", render' a) | a <- authors' ]
+ template = case compileTemplate (T.pack $ writerTemplate opts) of
+ Left e -> error e
+ Right t -> t
if writerStandalone opts
- then return $ renderTemplate context $ writerTemplate opts
+ then return $ renderTemplate template (varListToJSON context)
else return main
-- | Return man representation of notes.