From 4e34d366df31937cdc69b6b366355f10a84c16b2 Mon Sep 17 00:00:00 2001 From: despresc Date: Sat, 4 Apr 2020 16:35:42 -0400 Subject: Adapt to the newest Table type, fix some previous adaptation issues - Writers.Native is now adapted to the new Table type. - Inline captions should now be conditionally wrapped in a Plain, not a Para block. - The toLegacyTable function now lives in Writers.Shared. --- src/Text/Pandoc/Lua/Marshaling/AST.hs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/Text/Pandoc/Lua/Marshaling') diff --git a/src/Text/Pandoc/Lua/Marshaling/AST.hs b/src/Text/Pandoc/Lua/Marshaling/AST.hs index db9f097ef..f314649f0 100644 --- a/src/Text/Pandoc/Lua/Marshaling/AST.hs +++ b/src/Text/Pandoc/Lua/Marshaling/AST.hs @@ -21,7 +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 Text.Pandoc.Writers.Shared (toLegacyTable) import qualified Foreign.Lua as Lua import qualified Text.Pandoc.Lua.Util as LuaUtil @@ -168,7 +168,7 @@ pushBlock = \case Para blcks -> pushViaConstructor "Para" blcks Plain blcks -> pushViaConstructor "Plain" blcks RawBlock f cs -> pushViaConstructor "RawBlock" f cs - Table _ blkCapt specs _ thead tbody tfoot -> + 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 @@ -195,12 +195,11 @@ peekBlock idx = defineHowTo "get Block value" $ do "RawBlock" -> uncurry RawBlock <$> elementContent "Table" -> (\(capt, aligns, widths, headers, body) -> Table nullAttr - (Caption Nothing $ maybePara capt) + (Caption Nothing $ maybePlain capt) (zip aligns (map strictPos widths)) - 0 - [toRow headers] - (map toRow body) - []) + (TableHead nullAttr [toRow headers]) + [TableBody nullAttr 0 [] (map toRow body)] + (TableFoot nullAttr [])) <$> elementContent _ -> Lua.throwException ("Unknown block type: " <> tag) where @@ -208,10 +207,10 @@ 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) + strictPos w = if w > 0 then ColWidth w else ColWidthDefault + maybePlain [] = [] + maybePlain x = [Plain x] + toRow = Row nullAttr . map (\blk -> Cell nullAttr AlignDefault 1 1 blk) -- | Push an inline element to the top of the lua stack. pushInline :: Inline -> Lua () -- cgit v1.2.3