Skip to content

Commit

Permalink
✨ Vditor 所见即所得模式支持链接引用定义 Vanessa219/vditor#55
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Mar 7, 2020
1 parent ba2aca0 commit 0d689ca
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 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.

2 changes: 1 addition & 1 deletion test/spinv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

var spinVditorDOMTests = []*parseTest{

{"105", "<p data-block=\"0\">[1]</p><p data-block=\"0\" data-type=\"linkRefDefs\">[1]: f<wbr>\n</p>", "<p data-block=\"0\"><span data-type=\"link-ref\" data-link-text=\"1\" data-link-label=\"1\">1</span>\n</p><p data-block=\"0\" data-type=\"link-ref-defs\">[1]: f<wbr>\n</p>"},
{"105", "<p data-block=\"0\"><span data-type=\"link-ref\" data-link-text=\"1\" data-link-label=\"1\">1</span>\n</p><p data-block=\"0\" data-type=\"link-ref-defs\">[1]: f<wbr>\n</p>", "<p data-block=\"0\"><span data-type=\"link-ref\" data-link-text=\"1\" data-link-label=\"1\">1</span>\n</p><p data-block=\"0\" data-type=\"link-ref-defs\">[1]: f<wbr>\n</p>"},
{"104", "<a href=\"\" title=\"baz\">foo</a>", "<p data-block=\"0\"><a href=\"\"baz\"\">foo</a>\n</p>"},
{"103", "<p data-block=\"0\"><strong data-marker=\"**\">foo\n<em data-marker=\"*\">ba<wbr></em></strong>\n</p>", "<p data-block=\"0\"><strong data-marker=\"**\">foo\n<em data-marker=\"*\">ba<wbr></em></strong>\n</p>"},
{"102", "<p data-block=\"0\"><strong data-marker=\"**\">foo<em>\u200b\nb<wbr></em></strong>\n</p>", "<p data-block=\"0\"><strong data-marker=\"**\">foo\n<em data-marker=\"*\">b<wbr></em></strong>\n</p>"},
Expand Down
12 changes: 8 additions & 4 deletions vditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,14 @@ func (lute *Lute) genASTByVditorDOM(n *html.Node, tree *parse.Tree) {
if nil == n.FirstChild {
break
}

if "link-ref" == dataType {
node.Type = ast.NodeText
node.Tokens = []byte("[" + lute.domAttrValue(n, "data-link-text") + "][" + lute.domAttrValue(n, "data-link-label") + "]")
tree.Context.Tip.AppendChild(node)
return
}

var codeTokens []byte
if parse.Zwsp == n.FirstChild.Data && "" == lute.domAttrValue(n, "style") && nil != n.FirstChild.NextSibling {
codeTokens = []byte(n.FirstChild.NextSibling.FirstChild.Data)
Expand All @@ -803,10 +811,6 @@ func (lute *Lute) genASTByVditorDOM(n *html.Node, tree *parse.Tree) {
} else if "code-inline" == dataType {
node.Tokens = codeTokens
tree.Context.Tip.AppendChild(node)
} else if "link-ref" == dataType {
node.Type = ast.NodeText
node.Tokens = []byte("[" + lute.domAttrValue(n, "link-text") + "][" + lute.domAttrValue(n, "link-label") + "]")
tree.Context.Tip.AppendChild(node)
}
return
case atom.Font:
Expand Down

0 comments on commit 0d689ca

Please sign in to comment.