diff --git a/parser/table.go b/parser/table.go index 645e24c..36d7977 100644 --- a/parser/table.go +++ b/parser/table.go @@ -153,9 +153,24 @@ func matchTableCellTokens(tokens []*tokenizer.Token) (int, bool) { } pipes := 0 - for _, token := range tokens { + escapeNextPipe := false + for i, token := range tokens { + if token.Type == tokenizer.Backslash { + escapeNextPipe = true + continue + } if token.Type == tokenizer.Pipe { - pipes++ + if escapeNextPipe { + tokens[i].Type = "" + tokens[i].Value = "|" + tokens[i-1].Type = "" + tokens[i-1].Value = "" + escapeNextPipe = false + } else { + pipes++ + } + } else { + escapeNextPipe = false } } cells := tokenizer.Split(tokens, tokenizer.Pipe) diff --git a/parser/tests/table_test.go b/parser/tests/table_test.go index da55fcd..34d2ba4 100644 --- a/parser/tests/table_test.go +++ b/parser/tests/table_test.go @@ -85,6 +85,28 @@ func TestTableParser(t *testing.T) { }, }, }, + { + text: "| header |\n| --- |\n| cell\\|\\|cell |\n", + node: &ast.Table{ + Header: []ast.Node{ + &ast.Paragraph{ + Children: []ast.Node{ + &ast.Text{Content: "header"}, + }, + }, + }, + Delimiter: []string{"---"}, + Rows: [][]ast.Node{ + { + &ast.Paragraph{ + Children: []ast.Node{ + &ast.Text{Content: "cell||cell"}, + }, + }, + }, + }, + }, + }, } for _, test := range tests {