all repos — grayfriday @ f8378658c0b0a9f073eade7aa8f652d94b594219

blackfriday fork with a few changes

Fix rendering of tables

Add proper capture groups to fix the order of bits and pieces.
Vytautas Ĺ altenis vytas@rtfb.lt
Mon, 09 Nov 2015 21:57:27 +0200
commit

f8378658c0b0a9f073eade7aa8f652d94b594219

parent

d1b544e27876215d6e6dd56bdf7aebb3d2f340a9

1 files changed, 20 insertions(+), 16 deletions(-)

jump to
M block.goblock.go

@@ -689,23 +689,25 @@ }

var body bytes.Buffer - for i < len(data) { - pipes, rowStart := 0, i - for ; data[i] != '\n'; i++ { - if data[i] == '|' { - pipes++ + body.Write(p.r.CaptureWrites(func() { + for i < len(data) { + pipes, rowStart := 0, i + for ; data[i] != '\n'; i++ { + if data[i] == '|' { + pipes++ + } } - } - if pipes == 0 { - i = rowStart - break + if pipes == 0 { + i = rowStart + break + } + + // include the newline in data sent to tableRow + i++ + p.tableRow(data[rowStart:i], columns, false) } - - // include the newline in data sent to tableRow - i++ - p.tableRow(&body, data[rowStart:i], columns, false) - } + })) p.r.Table(header.Bytes(), body.Bytes(), columns)

@@ -819,12 +821,14 @@ if col != colCount {

return } - p.tableRow(out, header, columns, true) + out.Write(p.r.CaptureWrites(func() { + p.tableRow(header, columns, true) + })) size = i + 1 return } -func (p *parser) tableRow(out *bytes.Buffer, data []byte, columns []int, header bool) { +func (p *parser) tableRow(data []byte, columns []int, header bool) { i, col := 0, 0 var rowWork bytes.Buffer