aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Lua/Module/Pandoc.hs
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2021-11-06 11:00:26 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2021-11-06 09:04:29 -0700
commit6b462e59332242c18ea38a721ae672b88f33d621 (patch)
treec33d9d0fe2835cfbaddb7d84b58e2ae5736d9381 /src/Text/Pandoc/Lua/Module/Pandoc.hs
parentee2f0021f9b59f0bca6eabf4884641da7a09e21d (diff)
downloadpandoc-6b462e59332242c18ea38a721ae672b88f33d621.tar.gz
Lua: allow to pass custom reader options to `pandoc.read`
Reader options can now be passed as an optional third argument to `pandoc.read`. The object can either be a table or a ReaderOptions value like `PANDOC_READER_OPTIONS`. Creating new ReaderOptions objects is possible through the new constructor `pandoc.ReaderOptions`. Closes: #7656
Diffstat (limited to 'src/Text/Pandoc/Lua/Module/Pandoc.hs')
-rw-r--r--src/Text/Pandoc/Lua/Module/Pandoc.hs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Lua/Module/Pandoc.hs b/src/Text/Pandoc/Lua/Module/Pandoc.hs
index 33432b4d8..8f42a2988 100644
--- a/src/Text/Pandoc/Lua/Module/Pandoc.hs
+++ b/src/Text/Pandoc/Lua/Module/Pandoc.hs
@@ -42,6 +42,8 @@ import Text.Pandoc.Lua.Marshaling.Attr (mkAttr, mkAttributeList)
import Text.Pandoc.Lua.Marshaling.List (List (..))
import Text.Pandoc.Lua.Marshaling.ListAttributes ( mkListAttributes
, peekListAttributes)
+import Text.Pandoc.Lua.Marshaling.ReaderOptions ( peekReaderOptions
+ , pushReaderOptions)
import Text.Pandoc.Lua.Marshaling.SimpleTable (mkSimpleTable)
import Text.Pandoc.Lua.Module.Utils (sha1)
import Text.Pandoc.Lua.PandocLua (PandocLua, liftPandocLua,
@@ -355,6 +357,12 @@ otherConstructors =
, mkAttributeList
, mkListAttributes
, mkSimpleTable
+
+ , defun "ReaderOptions"
+ ### liftPure id
+ <#> parameter peekReaderOptions "ReaderOptions|table" "opts" "reader options"
+ =#> functionResult pushReaderOptions "ReaderOptions" "new object"
+ #? "Creates a new ReaderOptions value."
]
stringConstants :: [Field e]
@@ -405,10 +413,12 @@ functions =
=?> "output string, or error triple"
, defun "read"
- ### (\content mformatspec -> do
+ ### (\content mformatspec mreaderOptions -> do
let formatSpec = fromMaybe "markdown" mformatspec
+ readerOptions = fromMaybe def mreaderOptions
res <- Lua.liftIO . runIO $ getReader formatSpec >>= \case
- (TextReader r, es) -> r def{ readerExtensions = es } content
+ (TextReader r, es) -> r readerOptions{ readerExtensions = es }
+ content
_ -> throwError $ PandocSomeError
"Only textual formats are supported"
case res of
@@ -422,6 +432,8 @@ functions =
throwM e)
<#> parameter peekText "string" "content" "text to parse"
<#> optionalParameter peekText "string" "formatspec" "format and extensions"
+ <#> optionalParameter peekReaderOptions "ReaderOptions" "reader_options"
+ "reader options"
=#> functionResult pushPandoc "Pandoc" "result document"
, sha1