comments, minor cleanups
Russ Ross russ@russross.com
Tue, 31 May 2011 16:28:07 -0600
M
block.go
→
block.go
@@ -562,29 +562,31 @@
func blockTable(out *bytes.Buffer, rndr *render, data []byte) int { var header_work bytes.Buffer i, columns, col_data := blockTableHeader(&header_work, rndr, data) - if i > 0 { - var body_work bytes.Buffer + if i == 0 { + return 0 + } - for i < len(data) { - pipes, row_start := 0, i - for ; i < len(data) && data[i] != '\n'; i++ { - if data[i] == '|' { - pipes++ - } - } + var body_work bytes.Buffer - if pipes == 0 || i == len(data) { - i = row_start - break + for i < len(data) { + pipes, row_start := 0, i + for ; i < len(data) && data[i] != '\n'; i++ { + if data[i] == '|' { + pipes++ } - - blockTableRow(&body_work, rndr, data[row_start:i], columns, col_data) - i++ } - if rndr.mk.Table != nil { - rndr.mk.Table(out, header_work.Bytes(), body_work.Bytes(), col_data, rndr.mk.Opaque) + if pipes == 0 || i == len(data) { + i = row_start + break } + + blockTableRow(&body_work, rndr, data[row_start:i], columns, col_data) + i++ + } + + if rndr.mk.Table != nil { + rndr.mk.Table(out, header_work.Bytes(), body_work.Bytes(), col_data, rndr.mk.Opaque) } return i
M
inline.go
→
inline.go
@@ -20,6 +20,7 @@ // data is the complete block being rendered
// offset is the number of valid chars before the current cursor func parseInline(out *bytes.Buffer, rndr *render, data []byte) { + // this is called recursively: enforce a maximum depth if rndr.nesting >= rndr.maxNesting { return }@@ -45,12 +46,12 @@ i = end
// call the trigger parser := rndr.inline[data[end]] - end = parser(out, rndr, data, i) - - if end == 0 { // no action from the callback + if consumed := parser(out, rndr, data, i); consumed == 0 { + // no action from the callback; buffer the byte for later end = i + 1 } else { - i += end + // skip past whatever the callback used + i += consumed end = i } }