From 9c4dd985ec25e203de75736f1c2e1cbda63c538f Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Fri, 14 Apr 2023 14:18:14 -0700
Subject: [PATCH] Fix djot-reader.lua for tables.

Closes #10.
---
 djot-reader.lua | 44 +++++++++++++++++++++++---------------------
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/djot-reader.lua b/djot-reader.lua
index 6973868..ffcbcdf 100644
--- a/djot-reader.lua
+++ b/djot-reader.lua
@@ -167,30 +167,32 @@ function Renderer:table(node)
   local caption = {}
   local aligns = nil
   local widths = nil
-  for i=2,#node do
-    local row = node[i]
-    if row[1] == "caption" then
+  local content = node.c
+  for i=1,#content do
+    local row = content[i]
+    if row.t == "caption" then
       caption = self:render_children(row)
-    elseif row[1] == "row" then
-      if not aligns then
-        aligns = {}
-        widths = {}
-        for j=2,#row do
-          local align = row[j].align
-          if not align then
-            aligns[j - 1] = "AlignDefault"
-          elseif align == "center" then
-              aligns[j - 1] = "AlignCenter"
-          elseif align == "left" then
-              aligns[j - 1] = "AlignLeft"
-          elseif align == "right" then
-              aligns[j - 1] = "AlignRight"
-          end
-          widths[j - 1] = 0
+    elseif row.t == "row" then
+      local cells = {}
+      for j=1,#row.c do
+        cells[j] = self:render_node(row.c[j])
+        if not aligns then
+          aligns = {}
+          widths = {}
+            local align = row.c[j].align
+            if not align then
+              aligns[j] = "AlignDefault"
+            elseif align == "center" then
+                aligns[j] = "AlignCenter"
+            elseif align == "left" then
+                aligns[j] = "AlignLeft"
+            elseif align == "right" then
+                aligns[j] = "AlignRight"
+            end
+            widths[j] = 0
         end
       end
-      local cells = self:render_children(row)
-      if i == 2 and row.head then
+      if row.head then
         headers = cells
       else
         rows[#rows + 1] = cells
-- 
2.47.3

