Skip to content

Commit

Permalink
🎨 Improve parsing <br /> in table cell
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Oct 13, 2024
1 parent 7aafc23 commit ffbe851
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion javascript/lute.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion javascript/lute.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion parse/inline_html.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (t *Tree) parseInlineHTML(ctx *InlineContext) (ret *ast.Node) {
ctx.pos += len(tags)

if t.Context.ParseOption.ProtyleWYSIWYG {
if bytes.Equal(tags, []byte("<br />")) || bytes.Equal(tags, []byte("<br/>")) {
if bytes.EqualFold(tags, []byte("<br />")) || bytes.EqualFold(tags, []byte("<br/>")) || bytes.EqualFold(tags, []byte("<br>")) {
ret = &ast.Node{Type: ast.NodeBr}
return
} else if bytes.HasPrefix(tags, []byte("<span data-type=")) {
Expand Down
4 changes: 2 additions & 2 deletions parse/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (t *Tree) parseBackslash(block *ast.Node, ctx *InlineContext) *ast.Node {
if '<' == token && nil != t.Context.oldtip && ast.NodeTable == t.Context.oldtip.Type {
// 表格单元格内存在多行时末尾输入转义符 `\` 导致 `<br />` 暴露 https://github.com/siyuan-note/siyuan/issues/7725
isBr := ctx.tokens[ctx.pos:]
if bytes.HasPrefix(isBr, []byte("<br />")) {
if bytes.HasPrefix(isBr, []byte("<br />")) || bytes.HasPrefix(isBr, []byte("<br/>")) || bytes.HasPrefix(isBr, []byte("<br>")) {
return &ast.Node{Type: ast.NodeText, Tokens: backslash}
}
}
Expand All @@ -81,7 +81,7 @@ func (t *Tree) parseBackslash(block *ast.Node, ctx *InlineContext) *ast.Node {
if '<' == token && nil != t.Context.oldtip && ast.NodeTable == t.Context.oldtip.Type {
// 表格单元格内存在多行时末尾输入转义符 `\` 导致 `<br />` 暴露 https://github.com/siyuan-note/siyuan/issues/7725
isBr := ctx.tokens[ctx.pos+len(caret):]
if bytes.HasPrefix(isBr, []byte("<br />")) {
if bytes.HasPrefix(isBr, []byte("<br />")) || bytes.HasPrefix(isBr, []byte("<br/>")) || bytes.HasPrefix(isBr, []byte("<br>")) {
return &ast.Node{Type: ast.NodeText, Tokens: backslash}
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/m2p_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import (

var md2BlockDOMTests = []parseTest{

{"91", "| foo |\n|---|\n| bar <br> baz |\n", "<div data-node-id=\"20060102150405-1a2b3c4\" data-node-index=\"1\" data-type=\"NodeTable\" class=\"table\" updated=\"20060102150405\"><div contenteditable=\"false\"><table contenteditable=\"true\" spellcheck=\"false\"><colgroup><col /></colgroup><thead><tr><th>foo</th></tr></thead><tbody><tr><td>bar <br /> baz</td></tr></tbody></table><div class=\"protyle-action__table\"><div class=\"table__resize\"></div><div class=\"table__select\"></div></div></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"90", "| foo |\n|---|\n| bar <br /> baz |\n", "<div data-node-id=\"20060102150405-1a2b3c4\" data-node-index=\"1\" data-type=\"NodeTable\" class=\"table\" updated=\"20060102150405\"><div contenteditable=\"false\"><table contenteditable=\"true\" spellcheck=\"false\"><colgroup><col /></colgroup><thead><tr><th>foo</th></tr></thead><tbody><tr><td>bar <br /> baz</td></tr></tbody></table><div class=\"protyle-action__table\"><div class=\"table__resize\"></div><div class=\"table__select\"></div></div></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"89", "| foo |\n|---|\n| bar <br/> baz |\n", "<div data-node-id=\"20060102150405-1a2b3c4\" data-node-index=\"1\" data-type=\"NodeTable\" class=\"table\" updated=\"20060102150405\"><div contenteditable=\"false\"><table contenteditable=\"true\" spellcheck=\"false\"><colgroup><col /></colgroup><thead><tr><th>foo</th></tr></thead><tbody><tr><td>bar <br /> baz</td></tr></tbody></table><div class=\"protyle-action__table\"><div class=\"table__resize\"></div><div class=\"table__select\"></div></div></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"88", "```\nfoo\n```", "<div data-node-id=\"20060102150405-1a2b3c4\" data-node-index=\"1\" data-type=\"NodeCodeBlock\" class=\"code-block\" updated=\"20060102150405\"><div class=\"protyle-action\"><span class=\"protyle-action--first protyle-action__language\" contenteditable=\"false\"></span><span class=\"fn__flex-1\"></span><span class=\"b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--first protyle-action__copy\"><svg><use xlink:href=\"#iconCopy\"></use></svg></span><span class=\"b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--last protyle-action__menu\"><svg><use xlink:href=\"#iconMore\"></use></svg></span></div><div class=\"hljs\"><div></div><div contenteditable=\"true\" style=\"flex: 1\" spellcheck=\"false\">foo\n</div></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"87", "foo<kbd>bar</kbd>​baz", "<div data-node-id=\"20060102150405-1a2b3c4\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20060102150405\"><div contenteditable=\"true\" spellcheck=\"false\">foo <span data-type=\"kbd\">\u200bbar</span>\u200bbaz</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"86", " ```\n foo\n ```\n", "<div data-node-id=\"20060102150405-1a2b3c4\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20060102150405\"><div contenteditable=\"true\" spellcheck=\"false\"> <span data-type=\"code\">\u200b foo </span>\u200b</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
Expand Down

0 comments on commit ffbe851

Please sign in to comment.