diff options
| author | Albert Krewinkel <[email protected]> | 2022-10-03 09:55:10 +0200 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2022-10-03 08:47:32 -0700 |
| commit | 3b0e70072023d519cfb97d25ab668cf0284a5e24 (patch) | |
| tree | 50549a1602036f0a8910f0f591d1af9b4b438c42 /pandoc-lua-engine | |
| parent | 132931a49190e9ed7706f0e58d6e965b68c188c2 (diff) | |
Lua: add function `pandoc.write_classic`.
The function can be used to convert a classic writer into a new-style
writer by setting it as the value of `Writer`:
``` lua
Writer = pandoc.write_classic
```
or to fully restore the old behavior:
``` lua
function Writer (doc, opts)
PANDOC_DOCUMENT = doc
PANDOC_WRITER_OPTIONS = opts
load(PANDOC_SCRIPT_FILE)()
return pandoc.write_classic(doc, opts)
end
```
Diffstat (limited to 'pandoc-lua-engine')
| -rw-r--r-- | pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs index e708f4345..ec77e2df6 100644 --- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs +++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs @@ -40,6 +40,7 @@ import Text.Pandoc.Lua.Marshal.WriterOptions ( peekWriterOptions , pushWriterOptions) import Text.Pandoc.Lua.Module.Utils (sha1) import Text.Pandoc.Lua.PandocLua (PandocLua (unPandocLua), liftPandocLua) +import Text.Pandoc.Lua.Writer.Classic (runCustom) import Text.Pandoc.Options ( ReaderOptions (readerExtensions) , WriterOptions (writerExtensions) ) import Text.Pandoc.Process (pipeProcess) @@ -268,6 +269,17 @@ functions = "writer options") =#> functionResult (either pushLazyByteString pushText) "string" "result document" + + , defun "write_classic" + ### (\doc mwopts -> runCustom (fromMaybe def mwopts) doc) + <#> parameter peekPandoc "Pandoc" "doc" "document to convert" + <#> opt (parameter peekWriterOptions "WriterOptions" "writer_options" + "writer options") + =#> functionResult pushText "string" "rendered document" + #? (T.unlines + [ "Runs a classic custom Lua writer, using the functions defined" + , "in the current environment." + ]) ] where walkElement x f = |
