Skip to content

Commit

Permalink
🐛 Protyle 虚拟引用无法通过快捷键转换为引用 siyuan-note/siyuan#5953
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Sep 25, 2022
1 parent a9e5752 commit 156ca55
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion protyle.go
Expand Up @@ -1404,7 +1404,7 @@ func (lute *Lute) genASTContenteditable(n *html.Node, tree *parse.Tree) {

tree.Context.Tip.AppendChild(node)

if "search-mark" == dataType || "virtual-block-ref" == dataType {
if lute.isTempMarkSpan(dataType) {
// 搜索高亮标记认为是普通文本
node.Type = ast.NodeText
node.Tokens = []byte(util.DomText(n))
Expand Down Expand Up @@ -1980,3 +1980,7 @@ func (lute *Lute) removeInnerMarker0(n *html.Node, marker string) {
lute.removeInnerMarker0(child, marker)
}
}

func (lute *Lute) isTempMarkSpan(dataType string) bool {
return "search-mark" == dataType || "virtual-block-ref" == dataType
}
1 change: 1 addition & 0 deletions test/spin_block_test.go
Expand Up @@ -20,6 +20,7 @@ import (

var spinBlockDOMTests = []*parseTest{

{"150", "<div data-node-id=\"20220925225448-5k419wu\" data-node-index=\"0\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220925225502\"><div contenteditable=\"true\" spellcheck=\"false\"><span data-type=\"virtual-block-ref\"><span data-type=\"block-ref\" data-id=\"20220925224818-n7b8985\" data-subtype=\"s\">bar</span></span> test</div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20220925225448-5k419wu\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220925225502\"><div contenteditable=\"true\" spellcheck=\"false\"><span data-type=\"block-ref\" data-subtype=\"s\" data-id=\"20220925224818-n7b8985\">bar</span> test</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"149", "<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=\"inline-memo\" data-inline-memo-content=\"这里是对 bar 的备注\">bar</span>baz</div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<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=\"inline-memo\" data-inline-memo-content=\"这里是对 bar 的备注\">bar</span>baz</div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>"},
{"148", "<div data-node-id=\"20220916213304-uoayj2q\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220916213403\"><div contenteditable=\"true\" spellcheck=\"false\">foo<span data-type=\"search-mark\">bar</span>baz</div><div class=\"protyle-attr\" contenteditable=\"false\">&ZeroWidthSpace;</div></div>", "<div data-node-id=\"20220916213304-uoayj2q\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220916213403\"><div contenteditable=\"true\" spellcheck=\"false\">foobarbaz</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"147", "<div data-node-id=\"20220915195318-c629idi\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220915213441\"><div contenteditable=\"true\" spellcheck=\"false\"><span data-type=\"strong em\">foo</span><span data-type=\"em strong\">bar</span> </div><div class=\"protyle-attr\" contenteditable=\"false\">&ZeroWidthSpace;</div></div>", "<div data-node-id=\"20220915195318-c629idi\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220915213441\"><div contenteditable=\"true\" spellcheck=\"false\"><span data-type=\"strong em\">foobar</span></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
Expand Down
12 changes: 12 additions & 0 deletions vditor_wysiwyg.go
Expand Up @@ -303,6 +303,18 @@ func (lute *Lute) searchEmptyNodes(n *html.Node, emptyNodes *[]*html.Node) {
if html.CommentNode == n.Type {
*emptyNodes = append(*emptyNodes, n)
}
case atom.Span:
if lute.isTempMarkSpan(util.DomAttrValue(n, "data-type")) {
*emptyNodes = append(*emptyNodes, n)
var children []*html.Node
for c := n.FirstChild; c != nil; c = c.NextSibling {
children = append(children, c)
}
for _, c := range children {
n.InsertBefore(c)
}
return
}
default:
if "katex" == util.DomAttrValue(n, "class") {
*emptyNodes = append(*emptyNodes, n)
Expand Down

0 comments on commit 156ca55

Please sign in to comment.