From 4e34d366df31937cdc69b6b366355f10a84c16b2 Mon Sep 17 00:00:00 2001
From: despresc <christian.j.j.despres@gmail.com>
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 ++++++++++-----------
 src/Text/Pandoc/Lua/Walk.hs           | 24 ++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 11 deletions(-)

(limited to 'src/Text/Pandoc/Lua')

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 ()
diff --git a/src/Text/Pandoc/Lua/Walk.hs b/src/Text/Pandoc/Lua/Walk.hs
index 5b62001de..695c7b44e 100644
--- a/src/Text/Pandoc/Lua/Walk.hs
+++ b/src/Text/Pandoc/Lua/Walk.hs
@@ -59,6 +59,18 @@ instance Walkable (SingletonsList Inline) Row where
   walkM = walkRowM
   query = queryRow
 
+instance Walkable (SingletonsList Inline) TableHead where
+  walkM = walkTableHeadM
+  query = queryTableHead
+
+instance Walkable (SingletonsList Inline) TableBody where
+  walkM = walkTableBodyM
+  query = queryTableBody
+
+instance Walkable (SingletonsList Inline) TableFoot where
+  walkM = walkTableFootM
+  query = queryTableFoot
+
 instance Walkable (SingletonsList Inline) Caption where
   walkM = walkCaptionM
   query = queryCaption
@@ -102,6 +114,18 @@ instance Walkable (SingletonsList Block) Row where
   walkM = walkRowM
   query = queryRow
 
+instance Walkable (SingletonsList Block) TableHead where
+  walkM = walkTableHeadM
+  query = queryTableHead
+
+instance Walkable (SingletonsList Block) TableBody where
+  walkM = walkTableBodyM
+  query = queryTableBody
+
+instance Walkable (SingletonsList Block) TableFoot where
+  walkM = walkTableFootM
+  query = queryTableFoot
+
 instance Walkable (SingletonsList Block) Caption where
   walkM = walkCaptionM
   query = queryCaption
-- 
cgit v1.2.3