diff options
Diffstat (limited to 'rst_context.lua')
-rw-r--r-- | rst_context.lua | 115 |
1 files changed, 77 insertions, 38 deletions
diff --git a/rst_context.lua b/rst_context.lua index 64c2cd6..851bd7e 100644 --- a/rst_context.lua +++ b/rst_context.lua @@ -13,9 +13,9 @@ require "lpeg" -require help = "rst_helpers" +help = require "rst_helpers" -local dbg_write = help.dbg_write +local dbg_write = help.dbg_writef local C, Cb, Cc, Cg, Cmt, Cp, Cs, Ct, P, R, S, V, match = lpeg.C, lpeg.Cb, lpeg.Cc, lpeg.Cg, lpeg.Cmt, lpeg.Cp, lpeg.Cs, lpeg.Ct, lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.match @@ -615,36 +615,6 @@ function rst_context.table (str) end function rst_context.grid_table (tab) - local head - if tab.has_head then - head = [[ -\\setupTABLE[c][first] [background=color, backgroundcolor=grey, style=\tt] -\\setupTABLE[c][each] [frame=on] -\\setupTABLE[r][each] [frame=on] -\\bTABLE[split=repeat,option=stretch] -\\bTABLEhead -\\bTR - \\bTH first \\eTH - \\bTH second \\eTH - \\bTH third \\eTH - \\bTH fourth \\eTH -\\eTR -\\eTABLEhead -\\bTABLEbody -]] - else - head = [[ -\\setupTABLE[c][each] [frame=on] -\\setupTABLE[r][each] [frame=on] -\\bTABLE[split=repeat,option=stretch] -\\bTABLEbody -]] - end - local tail = [[ - -\\eTABLEbody -\\eTABLE -]] local body = "" for i,r in ipairs(tab.rows) do local isempty = true @@ -679,18 +649,87 @@ function rst_context.grid_table (tab) body = body .. row .. "\n" .. [[\\eTR]] .. "\n" end end + local head + if tab.has_head then + head = [[ +\\setupTABLE[c][first] [background=color, backgroundcolor=grey, style=\tt] +\\setupTABLE[c][each] [frame=on] +\\setupTABLE[r][each] [frame=on] +\\bTABLE[split=repeat,option=stretch] +\\bTABLEhead +\\bTR + \\bTH first \\eTH + \\bTH second \\eTH + \\bTH third \\eTH + \\bTH fourth \\eTH +\\eTR +\\eTABLEhead +\\bTABLEbody +]] + else + head = [[ +\\setupTABLE[c][each] [frame=on] +\\setupTABLE[r][each] [frame=on] +\\bTABLE[split=repeat,option=stretch] +\\bTABLEbody +]] + end + local tail = [[ + +\\eTABLEbody +\\eTABLE +]] return head .. body .. tail end -function rst_context.table_row (tab) - local tmp = [[\\bTR]] - for n, cell in ipairs(tab) do - tmp = tmp .. [[\\bTC]] .. cell .. [[\\eTC]] .. "\n" +function rst_context.simple_table(tab) + local head + if tab.has_head then + head = [[ +\\setupTABLE[c][first] [background=color, backgroundcolor=grey, style=\tt] +\\setupTABLE[c][each] [frame=on] +\\setupTABLE[r][each] [frame=on] +\\bTABLE[split=repeat,option=stretch] +\\bTABLEhead +\\bTR + \\bTH first \\eTH + \\bTH second \\eTH + \\bTH third \\eTH +\\eTR +\\eTABLEhead +\\bTABLEbody +]] + else + head = [[ +\\setupTABLE[c][each] [frame=on] +\\setupTABLE[r][each] [frame=on] +\\bTABLE[split=repeat,option=stretch] +\\bTABLEbody +]] end + local tail = [[ - tmp = tmp .. [[\\eTR +\\eTABLEbody +\\eTABLE ]] - return tmp + local body = "" + for nr,row in ipairs(tab) do + if not row.separator and not row.ignore then + dbg_write(">tr>" .. #row) + body = body .. [[\\bTR]] + for nc,cell in ipairs(row) do + dbg_write("%7s | ", cell.content) + if cell.span then + body = body .. string.format([=[\\bTC[nc=%s]%s\\eTC]=], cell.span, cell.content) + else + body = body .. [[\\bTC ]] .. cell.content .. [[\\eTC]] + end + end + dbg_write("\n") + body = body .. "\\\\eTR\n" + end + end + return head .. body .. tail end return rst_context |