From 9af5b1ca8bf849f12a21fe8a5a91ab4249cf5ff2 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Fri, 7 Jun 2024 17:56:49 +0200 Subject: Lua: add function `pandoc.template.get`. The function allows to specify a template with the same argument value that would be used with the `--template` command line parameter. Closes: #9854 Co-authored-by: Carsten Gips --- .../src/Text/Pandoc/Lua/Module/Template.hs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'pandoc-lua-engine/src') diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Template.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Template.hs index 69dc75955..9cca6fda4 100644 --- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Template.hs +++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Template.hs @@ -21,7 +21,7 @@ import Text.Pandoc.Lua.Marshal.Template (typeTemplate, peekTemplate, pushTemplat import Text.Pandoc.Lua.PandocLua (PandocLua (unPandocLua), liftPandocLua) import Text.Pandoc.Writers.Shared (metaToContext') import Text.Pandoc.Templates - ( compileTemplate, getDefaultTemplate, renderTemplate + ( compileTemplate, getDefaultTemplate, getTemplate, renderTemplate , runWithPartials, runWithDefaultPartials ) import qualified Data.Text as T @@ -91,14 +91,27 @@ functions = <#> opt (textParam "writer" ("name of the writer for which the template should be " <> "retrieved; defaults to the global `FORMAT`.")) - =#> functionResult pushText "string" - "raw template" + =#> functionResult pushText "string" "raw template" #? T.unlines [ "Returns the default template for a given writer as a string. An" , "error is thrown if no such template can be found." ] `since` makeVersion [2,17] + , defun "get" + ### (unPandocLua . getTemplate) + <#> stringParam "filename" "name of the template" + =#> textResult "content of template file" + #? T.unlines + [ "Retrieve text for a template." + , "" + , "This function first checks the resource paths for a file of this" + , "name; if none is found, the `templates` directory in the user data" + , "directory is checked. Returns the content of the file, or throws" + , "an error if no file is found." + ] + `since` makeVersion [3,2,1] + , defun "meta_to_context" ### (\meta blockWriterIdx inlineWriterIdx -> unPandocLua $ do let blockWriter blks = liftPandocLua $ do -- cgit v1.2.3