mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
comments, minor cleanups
This commit is contained in:
parent
b6e6530815
commit
921ac7d0be
38
block.go
38
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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user