From 921ac7d0be8144f68245b26c54cf079aa8a936ff Mon Sep 17 00:00:00 2001 From: Russ Ross Date: Tue, 31 May 2011 16:28:07 -0600 Subject: [PATCH] comments, minor cleanups --- block.go | 38 ++++++++++++++++++++------------------ inline.go | 9 +++++---- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/block.go b/block.go index 5781a2d..9ced72e 100644 --- a/block.go +++ b/block.go @@ -562,29 +562,31 @@ func blockFencedCode(out *bytes.Buffer, rndr *render, data []byte) int { 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 + + for i < len(data) { + pipes, row_start := 0, i + for ; i < len(data) && data[i] != '\n'; i++ { + if data[i] == '|' { + pipes++ } - - 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) + 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 diff --git a/inline.go b/inline.go index 6fbd369..21809c1 100644 --- a/inline.go +++ b/inline.go @@ -20,6 +20,7 @@ import ( // 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 @@ func parseInline(out *bytes.Buffer, rndr *render, data []byte) { // 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 } }