git.iko.soy/typeable/pandoc
on master help sign in
Templates: Change type of renderTemplate'.

Return value is now Text rather than being polymorphic. This makes room for upcoming removal of the TemplateTarget class from doctemplates. Other code modified accordingly, and should compile with both current and upcoming version of doctemplates.

commit1187ca3517b9fdd625e4dadda58b1fbf8862d55b authorJohn MacFarlane <jgm@berkeley.edu> dateTue 23 Jul 2019, 21:40 (7 years ago) parent54b50cb
5 files changed+14−15
pandoc.cabal+1−1 src/Text/Pandoc/Templates.hs+3−3 src/Text/Pandoc/Writers/Custom.hs+1−1 src/Text/Pandoc/Writers/MediaWiki.hs+3−3 src/Text/Pandoc/Writers/RTF.hs+6−7
pandoc.cabal+1−1
@@ -408,7 +408,7 @@ library
408408 JuicyPixels >= 3.1.6.1 && < 3.4,
409409 Glob >= 0.7 && < 0.11,
410410 cmark-gfm >= 0.2 && < 0.3,
411− doctemplates >= 0.2.1 && < 0.3,
411+ doctemplates >= 0.2.2.1 && < 0.4,
412412 network-uri >= 2.6 && < 2.7,
413413 network >= 2.6,
414414 http-client >= 0.4.30 && < 0.7,
src/Text/Pandoc/Templates.hs+3−3
@@ -22,7 +22,7 @@ import Control.Monad.Except (throwError)
2222import Data.Aeson (ToJSON (..))
2323import qualified Data.Text as T
2424import System.FilePath ((<.>), (</>))
25−import Text.DocTemplates (Template, TemplateTarget, applyTemplate,
25+import Text.DocTemplates (Template, applyTemplate,
2626 compileTemplate, renderTemplate, varListToJSON)
2727import Text.Pandoc.Class (PandocMonad, readDataFile)
2828import Text.Pandoc.Error
@@ -57,8 +57,8 @@ getDefaultTemplate writer = do
5757
5858-- | Like 'applyTemplate', but runs in PandocMonad and
5959-- raises an error if compilation fails.
60−renderTemplate' :: (PandocMonad m, ToJSON a, TemplateTarget b)
61− => String -> a -> m b
60+renderTemplate' :: (PandocMonad m, ToJSON a)
61+ => String -> a -> m T.Text
6262renderTemplate' template context =
6363 case applyTemplate (T.pack template) context of
6464 Left e -> throwError (PandocTemplateError e)
src/Text/Pandoc/Writers/Custom.hs+1−1
@@ -114,7 +114,7 @@ writeCustom luaFile opts doc@(Pandoc meta _) = do
114114 Just tpl ->
115115 case applyTemplate (pack tpl) $ setField "body" body context of
116116 Left e -> throw (PandocTemplateError e)
117− Right r -> return (pack r)
117+ Right r -> return r
118118
119119docToCustom :: WriterOptions -> Pandoc -> Lua String
120120docToCustom opts (Pandoc (Meta metamap) blocks) = do
src/Text/Pandoc/Writers/MediaWiki.hs+3−3
@@ -66,9 +66,9 @@ pandocToMediaWiki (Pandoc meta blocks) = do
6666 let main = body ++ notes
6767 let context = defField "body" main
6868 $ defField "toc" (writerTableOfContents opts) metadata
69− pack <$> case writerTemplate opts of
70− Nothing -> return main
71− Just tpl -> renderTemplate' tpl context
69+ case writerTemplate opts of
70+ Nothing -> return $ pack main
71+ Just tpl -> renderTemplate' tpl context
7272
7373-- | Escape special characters for MediaWiki.
7474escapeString :: String -> String
src/Text/Pandoc/Writers/RTF.hs+6−7
@@ -112,13 +112,12 @@ writeRTF options doc = do
112112 -- of the toc rather than a boolean:
113113 . defField "toc" toc
114114 else id) metadata
115− T.pack <$>
116− case writerTemplate options of
117− Just tpl -> renderTemplate' tpl context
118− Nothing -> return $
119− case reverse body of
120− ('\n':_) -> body
121− _ -> body ++ "\n"
115+ case writerTemplate options of
116+ Just tpl -> renderTemplate' tpl context
117+ Nothing -> return $ T.pack $
118+ case reverse body of
119+ ('\n':_) -> body
120+ _ -> body ++ "\n"
122121
123122-- | Convert unicode characters (> 127) into rich text format representation.
124123handleUnicode :: String -> String