diff options
| author | Albert Krewinkel <[email protected]> | 2021-12-31 18:59:52 +0100 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2022-01-04 11:55:59 -0800 |
| commit | 0d1d52f0a00753691663572da5f87dd4791d65fd (patch) | |
| tree | 777cc38c1062669d44ce0fc1cc493d74e8d150cd /src | |
| parent | 5c53837259b341ddd00eea926f0297cfc963d816 (diff) | |
Lua: add function `pandoc.write`
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Lua/Module/Pandoc.hs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Lua/Module/Pandoc.hs b/src/Text/Pandoc/Lua/Module/Pandoc.hs index 350934b80..e9603f827 100644 --- a/src/Text/Pandoc/Lua/Module/Pandoc.hs +++ b/src/Text/Pandoc/Lua/Module/Pandoc.hs @@ -36,9 +36,11 @@ import Text.Pandoc.Lua.Marshal.ReaderOptions ( peekReaderOptions , pushReaderOptions) import Text.Pandoc.Lua.Module.Utils (sha1) import Text.Pandoc.Lua.PandocLua (PandocLua (unPandocLua), liftPandocLua) -import Text.Pandoc.Options (ReaderOptions (readerExtensions)) +import Text.Pandoc.Options ( ReaderOptions (readerExtensions) + , WriterOptions (writerExtensions) ) import Text.Pandoc.Process (pipeProcess) import Text.Pandoc.Readers (Reader (..), getReader) +import Text.Pandoc.Writers (Writer (..), getWriter) import qualified HsLua as Lua import qualified Data.ByteString.Lazy as BL @@ -205,6 +207,23 @@ functions = <#> parameter peekInlineFuzzy "Inline" "inline" "element to traverse" <#> parameter peekFilter "Filter" "lua_filter" "filter functions" =#> functionResult pushInline "Inline" "modified Inline" + + , defun "write" + ### (\doc mformatspec mwriterOpts -> do + let formatSpec = fromMaybe "html" mformatspec + writerOpts = fromMaybe def mwriterOpts + unPandocLua $ getWriter formatSpec >>= \case + (TextWriter w, es) -> Right <$> + w writerOpts{ writerExtensions = es } doc + (ByteStringWriter w, es) -> Left <$> + w writerOpts{ writerExtensions = es } doc) + <#> parameter peekPandoc "Pandoc" "doc" "document to convert" + <#> optionalParameter peekText "string" "formatspec" + "format and extensions" + <#> optionalParameter peekWriterOptions "WriterOptions" "writer_options" + "writer options" + =#> functionResult (either pushLazyByteString pushText) "string" + "result document" ] where walkElement x f = |
