diff --git a/protyle.go b/protyle.go index b529fe64a..eae4ee861 100644 --- a/protyle.go +++ b/protyle.go @@ -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)) @@ -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 +} diff --git a/test/spin_block_test.go b/test/spin_block_test.go index 0813ace78..a3df498e1 100644 --- a/test/spin_block_test.go +++ b/test/spin_block_test.go @@ -20,6 +20,7 @@ import ( var spinBlockDOMTests = []*parseTest{ + {"150", "
bar test
", "
bar test
\u200b
"}, {"149", "
foobarbaz
", "
foobarbaz
"}, {"148", "
foobarbaz
", "
foobarbaz
\u200b
"}, {"147", "
foobar
", "
foobar
\u200b
"}, diff --git a/vditor_wysiwyg.go b/vditor_wysiwyg.go index ee830113b..d7ccd5de9 100644 --- a/vditor_wysiwyg.go +++ b/vditor_wysiwyg.go @@ -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)