aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Lua/Marshaling/AST.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc/Lua/Marshaling/AST.hs')
-rw-r--r--src/Text/Pandoc/Lua/Marshaling/AST.hs19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Lua/Marshaling/AST.hs b/src/Text/Pandoc/Lua/Marshaling/AST.hs
index a4087ad87..db9f097ef 100644
--- a/src/Text/Pandoc/Lua/Marshaling/AST.hs
+++ b/src/Text/Pandoc/Lua/Marshaling/AST.hs
@@ -21,6 +21,7 @@ import Foreign.Lua (Lua, Peekable, Pushable, StackIndex)
import Text.Pandoc.Definition
import Text.Pandoc.Lua.Util (defineHowTo, pushViaConstructor)
import Text.Pandoc.Lua.Marshaling.CommonState ()
+import Text.Pandoc.Shared (toLegacyTable)
import qualified Foreign.Lua as Lua
import qualified Text.Pandoc.Lua.Util as LuaUtil
@@ -167,8 +168,9 @@ pushBlock = \case
Para blcks -> pushViaConstructor "Para" blcks
Plain blcks -> pushViaConstructor "Plain" blcks
RawBlock f cs -> pushViaConstructor "RawBlock" f cs
- Table capt aligns widths headers rows ->
- pushViaConstructor "Table" capt aligns widths headers rows
+ Table _ blkCapt specs _ thead tbody tfoot ->
+ let (capt, aligns, widths, headers, rows) = toLegacyTable blkCapt specs thead tbody tfoot
+ in pushViaConstructor "Table" capt aligns widths headers rows
-- | Return the value at the given index as block if possible.
peekBlock :: StackIndex -> Lua Block
@@ -192,7 +194,13 @@ peekBlock idx = defineHowTo "get Block value" $ do
"Plain" -> Plain <$> elementContent
"RawBlock" -> uncurry RawBlock <$> elementContent
"Table" -> (\(capt, aligns, widths, headers, body) ->
- Table capt aligns widths headers body)
+ Table nullAttr
+ (Caption Nothing $ maybePara capt)
+ (zip aligns (map strictPos widths))
+ 0
+ [toRow headers]
+ (map toRow body)
+ [])
<$> elementContent
_ -> Lua.throwException ("Unknown block type: " <> tag)
where
@@ -200,6 +208,11 @@ peekBlock idx = defineHowTo "get Block value" $ do
elementContent :: Peekable a => Lua a
elementContent = LuaUtil.rawField idx "c"
+ strictPos w = if w > 0 then Just w else Nothing
+ maybePara [] = []
+ maybePara x = [Para x]
+ toRow = Row nullAttr . map (\blk -> Cell nullAttr Nothing 1 1 blk)
+
-- | Push an inline element to the top of the lua stack.
pushInline :: Inline -> Lua ()
pushInline = \case