Custom writer: assign default Pandoc object to global PANDOC_DOCUMENT
The default Pandoc object is now non-strict, i.e., only the parts of the document that are accessed will be marshaled to Lua. A special type is no longer necessary. This change also makes it possible to use the global variable with library functions such as `pandoc.utils.references`, or to inspect the document contents with `walk()`.
This commit is contained in:
parent
0610f16f7f
commit
993222d2c9
1 changed files with 3 additions and 9 deletions
|
@ -18,9 +18,10 @@ import HsLua as Lua
|
|||
import HsLua.Module.Version (pushVersion)
|
||||
import Paths_pandoc (version)
|
||||
import Text.Pandoc.Class.CommonState (CommonState)
|
||||
import Text.Pandoc.Definition (Pandoc (Pandoc), pandocTypesVersion)
|
||||
import Text.Pandoc.Definition (Pandoc, pandocTypesVersion)
|
||||
import Text.Pandoc.Error (PandocError)
|
||||
import Text.Pandoc.Lua.Marshal.CommonState (pushCommonState)
|
||||
import Text.Pandoc.Lua.Marshal.Pandoc (pushPandoc)
|
||||
import Text.Pandoc.Lua.Marshal.ReaderOptions (pushReaderOptionsReadonly)
|
||||
import Text.Pandoc.Lua.Orphans ()
|
||||
import Text.Pandoc.Options (ReaderOptions)
|
||||
|
@ -52,7 +53,7 @@ setGlobal global = case global of
|
|||
pushVersion pandocTypesVersion
|
||||
Lua.setglobal "PANDOC_API_VERSION"
|
||||
PANDOC_DOCUMENT doc -> do
|
||||
pushUD typePandocLazy doc
|
||||
pushPandoc doc
|
||||
Lua.setglobal "PANDOC_DOCUMENT"
|
||||
PANDOC_READER_OPTIONS ropts -> do
|
||||
pushReaderOptionsReadonly ropts
|
||||
|
@ -66,10 +67,3 @@ setGlobal global = case global of
|
|||
PANDOC_VERSION -> do
|
||||
pushVersion version
|
||||
Lua.setglobal "PANDOC_VERSION"
|
||||
|
||||
-- | Readonly and lazy pandoc objects.
|
||||
typePandocLazy :: LuaError e => DocumentedType e Pandoc
|
||||
typePandocLazy = deftype "Pandoc (lazy)" []
|
||||
[ readonly "meta" "document metadata" (push, \(Pandoc meta _) -> meta)
|
||||
, readonly "blocks" "content blocks" (push, \(Pandoc _ blocks) -> blocks)
|
||||
]
|
||||
|
|
Loading…
Add table
Reference in a new issue