summaryrefslogtreecommitdiff
path: root/rst_context.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-11 16:38:03 +0200
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-11 16:38:03 +0200
commitb3bfc5af1f3579496d0eef0151bdf7b1ab06cfac (patch)
tree0f9ca15a647a891fb272a89c7eb28b70627cd2c4 /rst_context.lua
parent92e8189f0833024f4ad53c013fc7bd568a9c3bf0 (diff)
downloadcontext-rst-b3bfc5af1f3579496d0eef0151bdf7b1ab06cfac.tar.gz
simple table
Diffstat (limited to 'rst_context.lua')
-rw-r--r--rst_context.lua115
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