Skip to content

Commit

Permalink
🎨 Vditor 支持 Fix Vanessa219/vditor#170
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Feb 24, 2020
1 parent 84fa000 commit 2a23254
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 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 test/spinv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

var spinVditorDOMTests = []*parseTest{

{"97", "<p data-block=\"0\"><strong data-marker=\"**\">foo\n</strong>b<wbr></p>", "<p data-block=\"0\"><strong data-marker=\"**\">foo</strong>\nb<wbr>\n</p>"},
{"96", "<p data-block=\"0\">​<code marker=\"`\">\u200bcode<wbr></code><code marker=\"`\">\u200bspan</code><span>\u200b</span></p>", "<p data-block=\"0\">\u200b<code marker=\"`\">\u200bcode<wbr>span</code>\u200b\n</p>"},
{"95", "<p data-block=\"0\"><strong><em><wbr>\u200b</em></strong></p>", ""},
{"94", "<p data-block=\"0\">\u200b<code marker=\"`\">\u200bcode\nspan<wbr></code>\u200b\n</p>", "<p data-block=\"0\">\u200b<code marker=\"`\">\u200bcode span<wbr></code>\u200b\n</p>"},
Expand Down
13 changes: 12 additions & 1 deletion vditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ func (lute *Lute) genASTByVditorDOM(n *html.Node, tree *parse.Tree) {
n.FirstChild.Data = strings.TrimRight(n.FirstChild.Data, " ")
n.InsertAfter(&html.Node{Type: html.TextNode, Data: " "})
}
if strings.HasSuffix(n.FirstChild.Data, "\n") {
n.FirstChild.Data = strings.TrimRight(n.FirstChild.Data, "\n")
n.InsertAfter(&html.Node{Type: html.TextNode, Data: "\n"})
}

tree.Context.Tip = node
defer tree.Context.ParentTip()
Expand Down Expand Up @@ -524,6 +528,10 @@ func (lute *Lute) genASTByVditorDOM(n *html.Node, tree *parse.Tree) {
n.FirstChild.Data = strings.TrimRight(n.FirstChild.Data, " ")
n.InsertAfter(&html.Node{Type: html.TextNode, Data: " "})
}
if strings.HasSuffix(n.FirstChild.Data, "\n") {
n.FirstChild.Data = strings.TrimRight(n.FirstChild.Data, "\n")
n.InsertAfter(&html.Node{Type: html.TextNode, Data: "\n"})
}

tree.Context.Tip = node
defer tree.Context.ParentTip()
Expand Down Expand Up @@ -562,7 +570,6 @@ func (lute *Lute) genASTByVditorDOM(n *html.Node, tree *parse.Tree) {
}

n.FirstChild.Data = strings.ReplaceAll(n.FirstChild.Data, parse.Zwsp, "")

if strings.HasPrefix(n.FirstChild.Data, " ") {
n.FirstChild.Data = strings.TrimLeft(n.FirstChild.Data, " ")
node.InsertBefore(&ast.Node{Type: ast.NodeText, Tokens: []byte(" ")})
Expand All @@ -571,6 +578,10 @@ func (lute *Lute) genASTByVditorDOM(n *html.Node, tree *parse.Tree) {
n.FirstChild.Data = strings.TrimRight(n.FirstChild.Data, " ")
n.InsertAfter(&html.Node{Type: html.TextNode, Data: " "})
}
if strings.HasSuffix(n.FirstChild.Data, "\n") {
n.FirstChild.Data = strings.TrimRight(n.FirstChild.Data, "\n")
n.InsertAfter(&html.Node{Type: html.TextNode, Data: "\n"})
}

tree.Context.Tip = node
defer tree.Context.ParentTip()
Expand Down

0 comments on commit 2a23254

Please sign in to comment.