A better fix for counting columns

This commit is contained in:
Vytautas Šaltenis 2018-08-19 00:03:03 +03:00
parent 289c7041c7
commit 3259c6dc4b

View File

@ -818,7 +818,7 @@ func (p *Markdown) tableHeader(data []byte) (size int, columns []CellAlignFlags)
if data[0] == '|' { if data[0] == '|' {
colCount-- colCount--
} }
lastPipe := backupWindowsNewline(i, data) lastPipe := backtrackAnyNewlines(data, i)
if lastPipe < len(data) && data[lastPipe] == '|' && !isBackslashEscaped(data, lastPipe) { if lastPipe < len(data) && data[lastPipe] == '|' && !isBackslashEscaped(data, lastPipe) {
colCount-- colCount--
} }
@ -1652,3 +1652,12 @@ func backupWindowsNewline(i int, data []byte) int {
} }
return i return i
} }
// backtrackAnyNewlines decrements i until it hits any non-newline character or
// becomes zero.
func backtrackAnyNewlines(data []byte, i int) int {
for i > 0 && i < len(data) && iseol(data[i]) {
i--
}
return i
}