From 993222d2c9c94cbf51f06528b79ffddd56b9da46 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Sun, 19 Dec 2021 23:04:31 +0100 Subject: 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()`. --- src/Text/Pandoc/Lua/Global.hs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Text/Pandoc/Lua/Global.hs b/src/Text/Pandoc/Lua/Global.hs index c7b50a25f..cf82890c6 100644 --- a/src/Text/Pandoc/Lua/Global.hs +++ b/src/Text/Pandoc/Lua/Global.hs @@ -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) - ] -- cgit v1.2.3