Skip to content

Commit

Permalink
🐛 Fix Protyle link anchor text nested HTML tag parsing issue siyuan-n…
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Nov 4, 2024
1 parent 6639d83 commit 7bd5d54
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 4 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 @@ -121,7 +121,7 @@ func (t *Tree) parseInlineHTML(ctx *InlineContext) (ret *ast.Node) {
}
ctx.pos += len(tags)

if t.Context.ParseOption.ProtyleWYSIWYG && nil == ctx.brackets /* 方括号后跟标签的情况不处理 [<strong> */ {
if t.Context.ParseOption.ProtyleWYSIWYG {
if bytes.EqualFold(tags, []byte("<br />")) || bytes.EqualFold(tags, []byte("<br/>")) || bytes.EqualFold(tags, []byte("<br>")) {
ret = &ast.Node{Type: ast.NodeBr}
return
Expand Down
4 changes: 4 additions & 0 deletions parse/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ func processNestedNode(n *ast.Node, tag string, tags *[]string, unlinks *[]*ast.
next := c.Next
if ast.NodeTextMark == c.Type || ast.NodeText == c.Type {
n.InsertBefore(c)
} else if ast.NodeLinkDest == c.Type {
if nil != n.Previous && ast.NodeTextMark == n.Previous.Type {
n.Previous.TextMarkAHref = string(c.Tokens)
}
}
c = next
}
Expand Down
2 changes: 1 addition & 1 deletion test/m2p_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var md2BlockDOMTests = []parseTest{
{"64", "**[foo](bar \"baz\")**", "<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=\"strong a\" data-href=\"bar\" data-title=\"baz\">foo</span></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"63", "|![foo](assets/bar-20211228205701-btntjdp.png \"abc\"){: style=\"width: 525px;\"}|\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>\u200b<span contenteditable=\"false\" data-type=\"img\" class=\"img\"><span> </span><span><span class=\"protyle-action protyle-icons\"><span class=\"protyle-icon protyle-icon--only\"><svg class=\"svg\"><use xlink:href=\"#iconMore\"></use></svg></span></span><img src=\"assets/bar-20211228205701-btntjdp.png\" data-src=\"assets/bar-20211228205701-btntjdp.png\" alt=\"foo\" title=\"abc\" style=\"width: 525px;\" /><span class=\"protyle-action__drag\"></span><span class=\"protyle-action__title\">abc</span></span><span> </span></span>\u200b</th></tr></thead><tbody></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>"},
{"62", "<div data-type=\"NodeAttributeView\" data-av-type=\"table\"></div>", "<div contenteditable=\"false\" data-av-id=\"20060102150405-1a2b3c4\" data-av-type=\"table\" data-node-id=\"20060102150405-1a2b3c4\" data-node-index=\"1\" data-type=\"NodeAttributeView\" class=\"av\" updated=\"20060102150405\"><div spellcheck=\"false\"></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"61", "[<strong>b3log</strong>](https://b3log.org)", "<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=\"a\" data-href=\"https://b3log.org\">&lt;strong&gt;b3log&lt;/strong&gt;</span></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"61", "[<strong>b3log</strong>](https://b3log.org)", "<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=\"a strong\" data-href=\"https://b3log.org\">b3log</span></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"60", "[`b3log`](https://b3log.org)", "<div data-node-id=\"20060102150405-1a2b3c4\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20060102150405\"><div contenteditable=\"true\" spellcheck=\"false\">\u200b<span data-type=\"a code\" data-href=\"https://b3log.org\">\u200bb3log</span>\u200b</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"59", "[![foo](https://b3log.org/images/brand/b3log-128.png)](https://b3log.org)", "<div data-node-id=\"20060102150405-1a2b3c4\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20060102150405\"><div contenteditable=\"true\" spellcheck=\"false\">\u200b<span contenteditable=\"false\" data-type=\"img\" class=\"img\"><span> </span><span><span class=\"protyle-action protyle-icons\"><span class=\"protyle-icon protyle-icon--only\"><svg class=\"svg\"><use xlink:href=\"#iconMore\"></use></svg></span></span><img src=\"https://b3log.org/images/brand/b3log-128.png\" data-src=\"https://b3log.org/images/brand/b3log-128.png\" alt=\"foo\" /><span class=\"protyle-action__drag\"></span><span class=\"img__net\"><svg><use xlink:href=\"#iconLanguage\"></use></svg></span><span class=\"protyle-action__title\"></span></span><span> </span></span><span data-type=\"a\" data-href=\"https://b3log.org\">https://b3log.org</span></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"58", "foo\n\nbar\n{: id=\"20221126231947-0000001\" style=\"color: red\"}", "<div data-node-id=\"20060102150405-1a2b3c4\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20060102150405\"><div contenteditable=\"true\" spellcheck=\"false\">foo</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div data-node-id=\"20221126231947-0000001\" data-node-index=\"2\" data-type=\"NodeParagraph\" class=\"p\" style=\"color: red\" updated=\"20221126231947\"><div contenteditable=\"true\" spellcheck=\"false\">bar</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
Expand Down
1 change: 1 addition & 0 deletions test/spin_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

var spinBlockDOMTests = []*parseTest{

{"232", "<div data-node-id=\"20241104224414-zw2bqmr\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20241104224424\"><div contenteditable=\"true\" spellcheck=\"false\">[<wbr><span data-type=\"strong\">foo</span></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20241104224414-zw2bqmr\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20241104224424\"><div contenteditable=\"true\" spellcheck=\"false\">[<wbr><span data-type=\"strong\">foo</span></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"231", "<div data-node-id=\"20241103085149-shu8xzh\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20241103085157\"><div contenteditable=\"true\" spellcheck=\"false\">:\n1<wbr></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20241103085149-shu8xzh\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20241103085157\"><div contenteditable=\"true\" spellcheck=\"false\">:\n1<wbr></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"230", "<div data-node-id=\"20240929215806-kilt4j6\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20240929215857\"><div contenteditable=\"true\" spellcheck=\"false\">​<span data-type=\"tag\">​Android</span>​<wbr><span data-type=\"tag\">​Linux</span>​</div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20240929215806-kilt4j6\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20240929215857\"><div contenteditable=\"true\" spellcheck=\"false\">\u200b<span data-type=\"tag\">\u200bAndroid<wbr>Linux</span>\u200b</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"229", "<div data-node-id=\"20240911224355-fpf8ug5\" data-node-index=\"2\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20240912103926\"><div contenteditable=\"true\" spellcheck=\"false\"><span data-type=\"strong em\">foo</span><span data-type=\"em\">\n\tbar</span></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20240911224355-fpf8ug5\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20240912103926\"><div contenteditable=\"true\" spellcheck=\"false\"><span data-type=\"strong em\">foo</span>\n\t<span data-type=\"em\">bar</span></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
Expand Down

0 comments on commit 7bd5d54

Please sign in to comment.