Pass ReaderOptions to custom readers as second parameter.
This commit is contained in:
parent
822f894984
commit
213913f025
3 changed files with 7 additions and 8 deletions
|
@ -6596,9 +6596,9 @@ is available by default. To see a sample custom reader:
|
|||
|
||||
pandoc --print-default-data-file reader.lua
|
||||
|
||||
Reader options are available via the global variable
|
||||
`PANDOC_READER_OPTIONS`, as expalined in the [Lua filters
|
||||
documentation].
|
||||
If you want your custom reader to have access to reader options
|
||||
(e.g. the tab stop setting), you give your Reader function a
|
||||
second `options` parameter.
|
||||
|
||||
A custom writer is a Lua script that defines a function
|
||||
that specifies how to render each element in a Pandoc AST.
|
||||
|
|
|
@ -82,6 +82,6 @@ G = P{ "Pandoc",
|
|||
Special = S"`\\" / pandoc.Str;
|
||||
}
|
||||
|
||||
function Reader(input)
|
||||
function Reader(input, opts)
|
||||
return lpeg.match(G, input)
|
||||
end
|
||||
|
|
|
@ -33,9 +33,7 @@ readCustom :: (PandocMonad m, MonadIO m, ToSources s)
|
|||
=> FilePath -> ReaderOptions -> s -> m Pandoc
|
||||
readCustom luaFile opts sources = do
|
||||
let input = sourcesToText $ toSources sources
|
||||
let globals = [ PANDOC_SCRIPT_FILE luaFile
|
||||
, PANDOC_READER_OPTIONS opts
|
||||
]
|
||||
let globals = [ PANDOC_SCRIPT_FILE luaFile ]
|
||||
res <- runLua $ do
|
||||
setGlobals globals
|
||||
stat <- dofileWithTraceback luaFile
|
||||
|
@ -43,13 +41,14 @@ readCustom luaFile opts sources = do
|
|||
-- to handle this more gracefully):
|
||||
when (stat /= Lua.OK)
|
||||
Lua.throwErrorAsException
|
||||
parseCustom input
|
||||
parseCustom input opts
|
||||
case res of
|
||||
Left msg -> throw msg
|
||||
Right doc -> return doc
|
||||
|
||||
parseCustom :: forall e. PeekError e
|
||||
=> Text
|
||||
-> ReaderOptions
|
||||
-> LuaE e Pandoc
|
||||
parseCustom = invoke @e "Reader"
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue