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.
This commit is contained in:
parent
54b50cb29a
commit
1187ca3517
5 changed files with 14 additions and 15 deletions
|
@ -408,7 +408,7 @@ library
|
|||
JuicyPixels >= 3.1.6.1 && < 3.4,
|
||||
Glob >= 0.7 && < 0.11,
|
||||
cmark-gfm >= 0.2 && < 0.3,
|
||||
doctemplates >= 0.2.1 && < 0.3,
|
||||
doctemplates >= 0.2.2.1 && < 0.4,
|
||||
network-uri >= 2.6 && < 2.7,
|
||||
network >= 2.6,
|
||||
http-client >= 0.4.30 && < 0.7,
|
||||
|
|
|
@ -22,7 +22,7 @@ import Control.Monad.Except (throwError)
|
|||
import Data.Aeson (ToJSON (..))
|
||||
import qualified Data.Text as T
|
||||
import System.FilePath ((<.>), (</>))
|
||||
import Text.DocTemplates (Template, TemplateTarget, applyTemplate,
|
||||
import Text.DocTemplates (Template, applyTemplate,
|
||||
compileTemplate, renderTemplate, varListToJSON)
|
||||
import Text.Pandoc.Class (PandocMonad, readDataFile)
|
||||
import Text.Pandoc.Error
|
||||
|
@ -57,8 +57,8 @@ getDefaultTemplate writer = do
|
|||
|
||||
-- | Like 'applyTemplate', but runs in PandocMonad and
|
||||
-- raises an error if compilation fails.
|
||||
renderTemplate' :: (PandocMonad m, ToJSON a, TemplateTarget b)
|
||||
=> String -> a -> m b
|
||||
renderTemplate' :: (PandocMonad m, ToJSON a)
|
||||
=> String -> a -> m T.Text
|
||||
renderTemplate' template context =
|
||||
case applyTemplate (T.pack template) context of
|
||||
Left e -> throwError (PandocTemplateError e)
|
||||
|
|
|
@ -114,7 +114,7 @@ writeCustom luaFile opts doc@(Pandoc meta _) = do
|
|||
Just tpl ->
|
||||
case applyTemplate (pack tpl) $ setField "body" body context of
|
||||
Left e -> throw (PandocTemplateError e)
|
||||
Right r -> return (pack r)
|
||||
Right r -> return r
|
||||
|
||||
docToCustom :: WriterOptions -> Pandoc -> Lua String
|
||||
docToCustom opts (Pandoc (Meta metamap) blocks) = do
|
||||
|
|
|
@ -66,9 +66,9 @@ pandocToMediaWiki (Pandoc meta blocks) = do
|
|||
let main = body ++ notes
|
||||
let context = defField "body" main
|
||||
$ defField "toc" (writerTableOfContents opts) metadata
|
||||
pack <$> case writerTemplate opts of
|
||||
Nothing -> return main
|
||||
Just tpl -> renderTemplate' tpl context
|
||||
case writerTemplate opts of
|
||||
Nothing -> return $ pack main
|
||||
Just tpl -> renderTemplate' tpl context
|
||||
|
||||
-- | Escape special characters for MediaWiki.
|
||||
escapeString :: String -> String
|
||||
|
|
|
@ -112,13 +112,12 @@ writeRTF options doc = do
|
|||
-- of the toc rather than a boolean:
|
||||
. defField "toc" toc
|
||||
else id) metadata
|
||||
T.pack <$>
|
||||
case writerTemplate options of
|
||||
Just tpl -> renderTemplate' tpl context
|
||||
Nothing -> return $
|
||||
case reverse body of
|
||||
('\n':_) -> body
|
||||
_ -> body ++ "\n"
|
||||
case writerTemplate options of
|
||||
Just tpl -> renderTemplate' tpl context
|
||||
Nothing -> return $ T.pack $
|
||||
case reverse body of
|
||||
('\n':_) -> body
|
||||
_ -> body ++ "\n"
|
||||
|
||||
-- | Convert unicode characters (> 127) into rich text format representation.
|
||||
handleUnicode :: String -> String
|
||||
|
|
Loading…
Reference in a new issue