@@ -33,13 +33,15 @@ StackValue instances for pandoc types.
33module Text.Pandoc.Lua.StackInstances () where
33module Text.Pandoc.Lua.StackInstances () where
35import Control.Applicative ((<|>))
35import Control.Applicative ((<|>))
36+import Control.Monad (when)
36import Foreign.Lua (FromLuaStack (peek), Lua, LuaInteger, LuaNumber, StackIndex,
37import Foreign.Lua (FromLuaStack (peek), Lua, LuaInteger, LuaNumber, StackIndex,
37 ToLuaStack (push), Type (..), throwLuaError, tryLua)
38 ToLuaStack (push), Type (..), throwLuaError, tryLua)
38import Text.Pandoc.Definition
39import Text.Pandoc.Definition
39import Text.Pandoc.Lua.Util (adjustIndexBy, getTable, pushViaConstructor)
40import Text.Pandoc.Lua.Util (adjustIndexBy, getTable, pushViaConstructor)
40−import Text.Pandoc.Shared (safeRead)
41+import Text.Pandoc.Shared (Element (Blk, Sec), safeRead)
42import qualified Foreign.Lua as Lua
43import qualified Foreign.Lua as Lua
44+import qualified Text.Pandoc.Lua.Util as LuaUtil
44instance ToLuaStack Pandoc where
46instance ToLuaStack Pandoc where
45 push (Pandoc meta blocks) =
47 push (Pandoc meta blocks) =
@@ -306,3 +308,27 @@ instance ToLuaStack LuaAttr where
307instance FromLuaStack LuaAttr where
309instance FromLuaStack LuaAttr where
308 peek idx = LuaAttr <$> peek idx
310 peek idx = LuaAttr <$> peek idx
313+-- Hierarchical elements
315+instance ToLuaStack Element where
316+ push (Blk blk) = push blk
317+ push (Sec lvl num attr label contents) = do
319+ LuaUtil.addValue "level" lvl
320+ LuaUtil.addValue "numbering" num
321+ LuaUtil.addValue "attr" (LuaAttr attr)
322+ LuaUtil.addValue "label" label
323+ LuaUtil.addValue "contents" contents
325+ Lua.setmetatable (-2)
327+ pushSecMetaTable :: Lua ()
328+ pushSecMetaTable = do
329+ inexistant <- Lua.newmetatable "PandocElementSec"
330+ when inexistant $ do
331+ LuaUtil.addValue "t" "Sec"