Skip to content

Commit

Permalink
🐛 Protyle Unable to copy HTML block properly siyuan-note/siyuan#11391
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed May 16, 2024
1 parent 769fc1d commit ce4169d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 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.

1 change: 1 addition & 0 deletions protyle.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,7 @@ func (lute *Lute) genASTByBlockDOM(n *html.Node, tree *parse.Tree) {
node.Type = ast.NodeHTMLBlock
content := util.DomAttrValue(n.FirstChild.NextSibling.FirstChild, "data-content")
content = html.UnescapeHTMLStr(content)
content = html.UnescapeHTMLStr(content) // 这里要反转义两次,因为编辑器会对 HTML 实体进行转义
node.Tokens = util.StrToBytes(content)
tree.Context.Tip.AppendChild(node)
return
Expand Down
2 changes: 2 additions & 0 deletions test/spin_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (

var spinBlockDOMTests = []*parseTest{

{"226", "<div data-node-id=\"20240516235535-qvvlsau\" data-type=\"NodeHTMLBlock\" class=\"render-node\" data-subtype=\"block\" updated=\"20240516235535\"><div class=\"protyle-icons\">\n <span aria-label=\"编辑\" class=\"b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--first protyle-action__edit\"><svg><use xlink:href=\"#iconEdit\"></use></svg></span>\n <span aria-label=\"更多\" class=\"b3-tooltips__nw b3-tooltips protyle-icon protyle-action__menu protyle-icon--last\"><svg><use xlink:href=\"#iconMore\"></use></svg></span>\n</div><div><protyle-html data-content=\"&amp;amp;lt;div&amp;amp;gt;\n&amp;amp;amp;lt;foo&amp;amp;amp;gt;&amp;amp;lt;bar&amp;amp;gt;\n&amp;amp;lt;/div&amp;amp;gt;\"></protyle-html><span style=\"position: absolute\">​</span></div><div class=\"protyle-attr\" contenteditable=\"false\"></div></div>", "<div data-node-id=\"20240516235535-qvvlsau\" data-node-index=\"1\" data-type=\"NodeHTMLBlock\" class=\"render-node\" updated=\"20240516235535\" data-subtype=\"block\"><div class=\"protyle-icons\"><span class=\"b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--first protyle-action__edit\"><svg><use xlink:href=\"#iconEdit\"></use></svg></span><span class=\"b3-tooltips__nw b3-tooltips protyle-icon protyle-action__menu protyle-icon--last\"><svg><use xlink:href=\"#iconMore\"></use></svg></span></div><div><protyle-html data-content=\"&lt;div&gt;\n&amp;lt;foo&amp;gt;&lt;bar&gt;\n&lt;/div&gt;\"></protyle-html><span style=\"position: absolute\">\u200b</span></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"225", "<div data-node-id=\"20240516235224-6p7n4u8\" data-type=\"NodeHTMLBlock\" class=\"render-node\" data-subtype=\"block\" updated=\"20240516235224\"><div class=\"protyle-icons\">\n <span aria-label=\"编辑\" class=\"b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--first protyle-action__edit\"><svg><use xlink:href=\"#iconEdit\"></use></svg></span>\n <span aria-label=\"更多\" class=\"b3-tooltips__nw b3-tooltips protyle-icon protyle-action__menu protyle-icon--last\"><svg><use xlink:href=\"#iconMore\"></use></svg></span>\n</div><div><protyle-html data-content=\"&amp;amp;lt;div&amp;amp;gt;\nfoo\n&amp;amp;lt;/div&amp;amp;gt;\"></protyle-html><span style=\"position: absolute\">​</span></div><div class=\"protyle-attr\" contenteditable=\"false\"></div></div>", "<div data-node-id=\"20240516235224-6p7n4u8\" data-node-index=\"1\" data-type=\"NodeHTMLBlock\" class=\"render-node\" updated=\"20240516235224\" data-subtype=\"block\"><div class=\"protyle-icons\"><span class=\"b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--first protyle-action__edit\"><svg><use xlink:href=\"#iconEdit\"></use></svg></span><span class=\"b3-tooltips__nw b3-tooltips protyle-icon protyle-action__menu protyle-icon--last\"><svg><use xlink:href=\"#iconMore\"></use></svg></span></div><div><protyle-html data-content=\"&lt;div&gt;\nfoo\n&lt;/div&gt;\"></protyle-html><span style=\"position: absolute\">\u200b</span></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"224", "<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=\"www.bing.com/search?q=&amp;quot;你好&amp;quot;\">在必应搜索 &quot;你好&quot;</span></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>", "<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=\"www.bing.com/search?q=&amp;quot;你好&amp;quot;\">在必应搜索 &quot;你好&quot;</span></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"223", "<div data-node-id=\"20240512120339-0lzlky8\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20240512123256\"><div contenteditable=\"true\" spellcheck=\"false\">​<span contenteditable=\"false\" data-type=\"img\" class=\"img\" style=\"width: 178px;\"><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/image-20240512120345-t8xr06r.png\" data-src=\"assets/image-20240512120345-t8xr06r.png\" alt=\"image\" style=\"width: 168px;\"><span class=\"protyle-action__drag\"></span><span class=\"protyle-action__title\"></span></span><span> </span></span><span contenteditable=\"false\" data-type=\"img\" class=\"img\" style=\"width: 157px;\"><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/image-20240512120345-t8xr06r.png\" data-src=\"assets/image-20240512120345-t8xr06r.png\" alt=\"image\" style=\"width: 147px;\"><span class=\"protyle-action__drag\"></span><span class=\"protyle-action__title\"></span></span><span> </span></span>1<wbr>​</div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20240512120339-0lzlky8\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20240512123256\"><div contenteditable=\"true\" spellcheck=\"false\">\u200b<span contenteditable=\"false\" data-type=\"img\" class=\"img\" style=\"width: 178px;\"><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/image-20240512120345-t8xr06r.png\" data-src=\"assets/image-20240512120345-t8xr06r.png\" alt=\"image\" style=\"width: 168px;\" /><span class=\"protyle-action__drag\"></span><span class=\"protyle-action__title\"></span></span><span> </span></span>\u200b<span contenteditable=\"false\" data-type=\"img\" class=\"img\" style=\"width: 157px;\"><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/image-20240512120345-t8xr06r.png\" data-src=\"assets/image-20240512120345-t8xr06r.png\" alt=\"image\" style=\"width: 147px;\" /><span class=\"protyle-action__drag\"></span><span class=\"protyle-action__title\"></span></span><span> </span></span>1<wbr></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"222", "<div data-node-id=\"20240512120339-0lzlky8\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20240512120512\"><div contenteditable=\"true\" spellcheck=\"false\">&ZeroWidthSpace;<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/image-20240512120345-t8xr06r.png\" data-src=\"assets/image-20240512120345-t8xr06r.png\" alt=\"image\"><span class=\"protyle-action__drag\"></span><span class=\"protyle-action__title\"></span></span><span> </span></span><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/image-20240512120345-t8xr06r.png\" data-src=\"assets/image-20240512120345-t8xr06r.png\" alt=\"image\"><span class=\"protyle-action__drag\"></span><span class=\"protyle-action__title\"></span></span><span> </span></span>&ZeroWidthSpace;</div><div class=\"protyle-attr\" contenteditable=\"false\">&ZeroWidthSpace;</div></div>", "<div data-node-id=\"20240512120339-0lzlky8\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20240512120512\"><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=\"assets/image-20240512120345-t8xr06r.png\" data-src=\"assets/image-20240512120345-t8xr06r.png\" alt=\"image\" /><span class=\"protyle-action__drag\"></span><span class=\"protyle-action__title\"></span></span><span> </span></span>\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/image-20240512120345-t8xr06r.png\" data-src=\"assets/image-20240512120345-t8xr06r.png\" alt=\"image\" /><span class=\"protyle-action__drag\"></span><span class=\"protyle-action__title\"></span></span><span> </span></span>\u200b</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
Expand Down

0 comments on commit ce4169d

Please sign in to comment.