Skip to content

Commit

Permalink
🎨 引用锚文本中粘贴行级元素后转换为普通文本 siyuan-note/siyuan#5493
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jul 22, 2022
1 parent 5ee1aac commit f3b7c70
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 28 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.

28 changes: 2 additions & 26 deletions protyle.go
Original file line number Diff line number Diff line change
Expand Up @@ -1105,19 +1105,7 @@ func (lute *Lute) genASTContenteditable(n *html.Node, tree *parse.Tree) {
node.AppendChild(&ast.Node{Type: ast.NodeOpenParen})
id := lute.domAttrValue(n, "data-id")
node.AppendChild(&ast.Node{Type: ast.NodeBlockRefID, Tokens: util.StrToBytes(id)})
var refText string
if nil != n.FirstChild {
refText = lute.domText(n.FirstChild)

// 引用锚文本中粘贴行级元素问题 https://github.com/siyuan-note/siyuan/issues/5342
if nil != n.FirstChild.NextSibling && atom.Span == n.FirstChild.NextSibling.DataAtom {
refText += lute.domText(n.FirstChild.NextSibling)
if remainText := n.FirstChild.NextSibling.NextSibling; nil != remainText && 0 == remainText.DataAtom {
refText += remainText.Data
}
n.FirstChild.NextSibling.Unlink()
}
}
refText := lute.domText(n)
refText = strings.TrimSpace(refText)
if "" == refText {
return
Expand Down Expand Up @@ -1145,19 +1133,7 @@ func (lute *Lute) genASTContenteditable(n *html.Node, tree *parse.Tree) {
node.AppendChild(&ast.Node{Type: ast.NodeLess})
id := lute.domAttrValue(n, "data-id")
node.AppendChild(&ast.Node{Type: ast.NodeFileAnnotationRefID, Tokens: util.StrToBytes(id)})
var refText string
if nil != n.FirstChild {
refText = lute.domText(n.FirstChild)

// 引用锚文本中粘贴行级元素问题 https://github.com/siyuan-note/siyuan/issues/5342
if nil != n.FirstChild.NextSibling && atom.Span == n.FirstChild.NextSibling.DataAtom {
refText += lute.domText(n.FirstChild.NextSibling)
if remainText := n.FirstChild.NextSibling.NextSibling; nil != remainText && 0 == remainText.DataAtom {
refText += remainText.Data
}
n.FirstChild.NextSibling.Unlink()
}
}
refText := lute.domText(n)
refText = strings.TrimSpace(refText)
if "" == refText {
return
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 @@ -20,6 +20,7 @@ import (

var spinBlockDOMTests = []*parseTest{

{"129", "<div data-node-id=\"20220722094231-31y15n6\" data-node-index=\"2\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220722100657\"><div contenteditable=\"true\" spellcheck=\"false\"><span data-type=\"block-ref\" data-subtype=\"s\" data-id=\"20201225212401-ru1scjs\"><span data-type=\"block-ref\" data-subtype=\"s\" data-id=\"20200813093015-u6bopdt\">foo</span><wbr>bar</span></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20220722094231-31y15n6\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220722100657\"><div contenteditable=\"true\" spellcheck=\"false\"><span data-type=\"block-ref\" data-subtype=\"s\" data-id=\"20201225212401-ru1scjs\">foo<wbr>bar</span></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"128", "<div data-node-id=\"20220713235221-2gl2xf3\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220714001629\"><div contenteditable=\"true\" spellcheck=\"false\"><span data-id=\"20200915214115-42b8zma\" data-subtype=\"s\" data-type=\"block-ref\">f<span data-type=\"block-ref\" data-subtype=\"s\" data-id=\"20201004184819-nj8ibyg\">bar</span><wbr>oo</span></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20220713235221-2gl2xf3\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220714001629\"><div contenteditable=\"true\" spellcheck=\"false\"><span data-type=\"block-ref\" data-subtype=\"s\" data-id=\"20200915214115-42b8zma\">fbar<wbr>oo</span></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>"},
{"127", "<div data-node-id=\"20220713234954-elld2zv\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220713235603\"><div contenteditable=\"true\" spellcheck=\"false\"><span data-type=\"file-annotation-ref\" data-subtype=\"s\" data-id=\"assets/test-20220713234144-dwfr7rq.pdf/20220713234503-yj3x0j6\">f<span data-type=\"file-annotation-ref\" data-subtype=\"s\" data-id=\"assets/test-20220713234144-dwfr7rq.pdf/20220713234503-yj3x0j6\">bar-P144-20220713234503</span><wbr>oo</span></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20220713234954-elld2zv\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220713235603\"><div contenteditable=\"true\" spellcheck=\"false\"><span data-type=\"file-annotation-ref\" data-subtype=\"s\" data-id=\"assets/test-20220713234144-dwfr7rq.pdf/20220713234503-yj3x0j6\">fbar-P144-20220713234503<wbr>oo</span></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"126", "<div data-node-id=\"20220630185723-sp8xkfi\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220630185907\"><div contenteditable=\"true\" spellcheck=\"false\">foo <wbr><code></code></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20220630185723-sp8xkfi\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220630185907\"><div contenteditable=\"true\" spellcheck=\"false\">foo <wbr></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
Expand Down

0 comments on commit f3b7c70

Please sign in to comment.