summaryrefslogtreecommitdiff
path: root/rst_context.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-12 16:00:29 +0200
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-12 16:00:29 +0200
commitf14eb1fcfb3bdac66b528d50c44003879935a5a1 (patch)
tree004a1a0b0f4b0931a4c079606dc3d765b8a76df1 /rst_context.lua
parent490d03e4fb8264a420d2990ef0c1e2e8add937ec (diff)
downloadcontext-rst-f14eb1fcfb3bdac66b528d50c44003879935a5a1.tar.gz
table headers. turned off line correction for tables
Diffstat (limited to 'rst_context.lua')
-rw-r--r--rst_context.lua147
1 files changed, 103 insertions, 44 deletions
diff --git a/rst_context.lua b/rst_context.lua
index b3c09a6..863f2da 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -518,7 +518,7 @@ function rst_context.option_list (str)
\\setupTABLE[c][first] [background=color, backgroundcolor=grey, style=\tt]
\\setupTABLE[c][each] [frame=off]
\\setupTABLE[r][each] [frame=off]
-\\bTABLE[split=repeat,option=stretch]
+\\bTABLE[split=yes,option=stretch]
\\bTABLEhead
\\bTR
\\bTH Option \\eTH
@@ -605,18 +605,79 @@ function rst_context.block_quote (tab)
]]
end
-function rst_context.table (str)
- return [[
-\\startlinecorrection
-]] .. str .. [[
+--function rst_context.table (str)
+ --return [[
+--\\startlinecorrection
+--]] .. str .. [[
-\\stoplinecorrection
-]]
-end
+--\\stoplinecorrection
+--]]
+--end
function rst_context.grid_table (tab)
local body = ""
- for i,r in ipairs(tab.rows) do
+ local nr = 1
+ local head
+ if tab.has_head then
+ head = [[
+\\setupTABLE[c][each] [frame=on]
+\\setupTABLE[r][each] [frame=on]
+%\\startlinecorrection
+\\bTABLE[split=repeat,option=stretch]
+\\bTABLEhead
+]]
+ while nr <= tab.head_end do
+ local r = tab.rows[nr]
+ --for i,r in ipairs(tab.rows) do
+ local isempty = true
+ for n, cell in ipairs(r) do
+ if cell.variant == "normal" then
+ isempty = false
+ break
+ end
+ end
+
+ if not isempty then
+ local row = [[\\bTR]]
+ for n,c in ipairs(r) do
+ if not (c.parent or
+ c.variant == "separator") then
+ local celltext = inline_parser:match(c.stripped)
+ if c.span.x or c.span.y then
+ local span_exp = "["
+ if c.span.x then
+ span_exp = span_exp .. "nc=" .. c.span.x .. ","
+ end
+ if c.span.y then
+ span_exp = span_exp .. "nr=" .. c.span.y
+ end
+ celltext = span_exp .. "] " .. celltext
+
+ end
+
+ row = row .. "\n " .. [[\\bTH ]] .. celltext .. [[\\eTH]]
+ end
+ end
+ head = head .. row .. "\n" .. [[\\eTR]] .. "\n"
+ end
+ nr = nr + 1
+ end
+ head = head .. [[
+\\eTABLEhead
+\\bTABLEbody
+]]
+ else
+ head = [[
+\\setupTABLE[c][each] [frame=on]
+\\setupTABLE[r][each] [frame=on]
+%\\startlinecorrection
+\\bTABLE[split=repeat,option=stretch]
+\\bTABLEbody
+]]
+ end
+ while nr <= #tab.rows do
+ local r = tab.rows[nr]
+ --for i,r in ipairs(tab.rows) do
local isempty = true
for n, cell in ipairs(r) do
if cell.variant == "normal" then
@@ -648,55 +709,49 @@ function rst_context.grid_table (tab)
end
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
-]]
+ nr = nr + 1
end
local tail = [[
\\eTABLEbody
\\eTABLE
+%\\stoplinecorrection
]]
return head .. body .. tail
end
+
function rst_context.simple_table(tab)
local head
+ local nr = 1
if tab.has_head then
- print(tab.head_end)
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]
+%\\startlinecorrection
+\\bTABLE[split=yes,option=stretch]
\\bTABLEhead
-\\bTR
- \\bTH first \\eTH
- \\bTH second \\eTH
- \\bTH third \\eTH
-\\eTR
+]]
+ while nr <= tab.head_end do
+ local row = tab[nr]
+ if not row.separator and not row.ignore then
+ dbg_write(">hr>" .. #row)
+ head = head .. [[\\bTR]]
+ for nc,cell in ipairs(row) do
+ dbg_write("%7s | ", cell.content)
+ if cell.span then
+ head = head .. string.format([=[\\bTH[nc=%s]%s\\eTH]=], cell.span, cell.content)
+ else
+ head = head .. [[\\bTH ]] .. cell.content .. [[\\eTH]]
+ end
+ end
+ dbg_write("\n")
+ head = head .. "\\\\eTR\n"
+ end
+ nr = nr + 1
+ end
+
+ head = head .. [[
\\eTABLEhead
\\bTABLEbody
]]
@@ -704,7 +759,8 @@ function rst_context.simple_table(tab)
head = [[
\\setupTABLE[c][each] [frame=on]
\\setupTABLE[r][each] [frame=on]
-\\bTABLE[split=repeat,option=stretch]
+%\\startlinecorrection
+\\bTABLE[split=yes,option=stretch]
\\bTABLEbody
]]
end
@@ -712,9 +768,11 @@ function rst_context.simple_table(tab)
\\eTABLEbody
\\eTABLE
+%\\stoplinecorrection
]]
local body = ""
- for nr,row in ipairs(tab) do
+ while nr <= #tab do
+ local row = tab[nr]
if not row.separator and not row.ignore then
dbg_write(">tr>" .. #row)
body = body .. [[\\bTR]]
@@ -729,6 +787,7 @@ function rst_context.simple_table(tab)
dbg_write("\n")
body = body .. "\\\\eTR\n"
end
+ nr = nr + 1
end
return head .. body .. tail
end