add backChar and use it
This commit is contained in:
parent
fade61e5b7
commit
7b6aa5cb3c
28
block.go
28
block.go
|
@ -463,10 +463,7 @@ func (p *Parser) html(data []byte, doRender bool) int {
|
|||
// the end of the block has been found
|
||||
if doRender {
|
||||
// trim newlines
|
||||
end := i
|
||||
for end > 0 && data[end-1] == '\n' {
|
||||
end--
|
||||
}
|
||||
end := backChar(data, i, '\n')
|
||||
finalizeHTMLBlock(p.addBlock(&HTMLBlockData{}, data[:end]))
|
||||
}
|
||||
|
||||
|
@ -532,14 +529,6 @@ func (p *Parser) htmlHr(data []byte, doRender bool) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
func skipAlnum(data []byte, i int) int {
|
||||
n := len(data)
|
||||
for i < n && isalnum(data[i]) {
|
||||
i++
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func (p *Parser) htmlFindTag(data []byte) (string, bool) {
|
||||
i := skipAlnum(data, 0)
|
||||
key := string(data[:i])
|
||||
|
@ -1621,3 +1610,18 @@ func skipUntilChar(data []byte, i int, c byte) int {
|
|||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func skipAlnum(data []byte, i int) int {
|
||||
n := len(data)
|
||||
for i < n && isalnum(data[i]) {
|
||||
i++
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func backChar(data []byte, i int, c byte) int {
|
||||
for i > 0 && data[i-1] == c {
|
||||
i--
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue