diff options
author | Philipp Gesang <pgesang@ix.urz.uni-heidelberg.de> | 2010-09-12 16:00:29 +0200 |
---|---|---|
committer | Philipp Gesang <pgesang@ix.urz.uni-heidelberg.de> | 2010-09-12 16:00:29 +0200 |
commit | f14eb1fcfb3bdac66b528d50c44003879935a5a1 (patch) | |
tree | 004a1a0b0f4b0931a4c079606dc3d765b8a76df1 | |
parent | 490d03e4fb8264a420d2990ef0c1e2e8add937ec (diff) | |
download | context-rst-f14eb1fcfb3bdac66b528d50c44003879935a5a1.tar.gz |
table headers. turned off line correction for tables
-rw-r--r-- | rst_context.lua | 147 | ||||
-rw-r--r-- | rst_helpers.lua | 28 | ||||
-rw-r--r-- | rst_parser.lua | 1 |
3 files changed, 117 insertions, 59 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 diff --git a/rst_helpers.lua b/rst_helpers.lua index 4ec28fe..d80fdbd 100644 --- a/rst_helpers.lua +++ b/rst_helpers.lua @@ -394,7 +394,7 @@ function helpers.table.create(raw) for nr, row in ipairs(newrows) do --newrows[nr] = newrows[nr] or {} local cell = row[nc] - dbg_writef("nc: %s, nr:%2s | %9s | ", nc, nr,cell.variant) + dbg_write("nc: %s, nr:%2s | %9s | ", nc, nr,cell.variant) if row.sepline or row.sephead or p.dashesonly:match(cell.content) or cell.variant == "separator" then -- separator; skipping and beginning new row @@ -403,11 +403,11 @@ function helpers.table.create(raw) newrows[nr][nc] = cell currentrow = currentrow + 1 newrow = true - dbg_writef("new >%24s< ", cell.stripped) - if cell.parent then dbg_writef("parent |") else dbg_writef("no par |") end + dbg_write("new >%24s< ", cell.stripped) + if cell.parent then dbg_write("parent |") else dbg_write("no par |") end else - dbg_writef("old >%24s< ", cell.stripped) - if cell.parent then dbg_writef("parent |") else dbg_writef("no par |") end + dbg_write("old >%24s< ", cell.stripped) + if cell.parent then dbg_write("parent |") else dbg_write("no par |") end if newrow then --newrows[currentrow] = cell newrows[nr][nc] = cell @@ -417,17 +417,17 @@ function helpers.table.create(raw) local par_row, par_col local parent if cell.parent then - --dbg_writef(" use %s,%2s | ", cell.parent.x, cell.parent.y) + --dbg_write(" use %s,%2s | ", cell.parent.x, cell.parent.y) par_row, par_col = self.resolve_parent(cell.parent.y, cell.parent.x, newrows) - dbg_writef(" use %s,%2s | ", par_col, par_row) + dbg_write(" use %s,%2s | ", par_col, par_row) else -- Using vertical predecessor. par_row, par_col = self.resolve_parent(nr-1,nc, newrows) - dbg_writef(" new %s,%2s | ", par_col, par_row) + dbg_write(" new %s,%2s | ", par_col, par_row) end parent = newrows[par_row][par_col] if newrows[nr].seppart then - dbg_writef("span++") + dbg_write("span++") parent.span.y = parent.span.y + 1 end @@ -447,7 +447,7 @@ function helpers.table.create(raw) end newrow = false end - dbg_writef("\n") + dbg_write("\n") newrows[nr][nc] = cell end -- for loop over rows end -- for loop over columns @@ -465,10 +465,10 @@ function helpers.table.create(raw) if cell.parent then field = field .. string.format(" %s,%2s",cell.parent.x, cell.parent.y) end - dbg_writef("%12s | ", field) - --dbg_writef("%10s | ",(cell.parent and "true" or "false")) + dbg_write("%12s | ", field) + --dbg_write("%10s | ",(cell.parent and "true" or "false")) end - dbg_writef("\n") + dbg_write("\n") end end @@ -542,7 +542,7 @@ function helpers.table.simple(raw) newrow.separator = true if nr > 1 and #raw > nr then -- Ends the header. rows.has_head = true - newrow.head_end = nr + rows.head_end = nr end elseif multispans[nr] then local spans = multispans[nr] diff --git a/rst_parser.lua b/rst_parser.lua index 54c3719..f9f29c1 100644 --- a/rst_parser.lua +++ b/rst_parser.lua @@ -215,7 +215,6 @@ local parser = P{ table_block = V"simple_table" + V"grid_table" - / rst.table , -------------------------------------------------------------------------------- |