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 b7e5612 commit 0e1f2c6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions 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.

10 changes: 10 additions & 0 deletions render/vditor_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,16 @@ func (r *VditorRenderer) renderImage(node *ast.Node, entering bool) ast.WalkStat

func (r *VditorRenderer) renderLink(node *ast.Node, entering bool) ast.WalkStatus {
if entering {
if 3 == node.LinkType {
text := string(node.ChildByType(ast.NodeLinkText).Tokens)
label := string(node.LinkRefLabel)
attrs := [][]string{{"data-type", "link-ref"}, {"data-link-text", text}, {"data-link-label", label}}
r.tag("span", attrs, false)
r.WriteString(text)
r.tag("/span", nil, false)
return ast.WalkStop
}

dest := node.ChildByType(ast.NodeLinkDest)
destTokens := dest.Tokens
destTokens = r.Tree.Context.RelativePath(destTokens)
Expand Down
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{

{"105", "<p data-block=\"0\">[1]</p><p data-block=\"0\" data-type=\"linkRefDefs\">[1]: f<wbr>\n</p>", "<p data-block=\"0\"><a href=\"\"baz\"\">foo</a>\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
9 changes: 9 additions & 0 deletions vditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,15 @@ 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.NodeLink
node.AppendChild(&ast.Node{Type: ast.NodeOpenBracket})
node.AppendChild(&ast.Node{Type: ast.NodeLinkText, Tokens: []byte(lute.domAttrValue(n, "link-text"))})
node.AppendChild(&ast.Node{Type: ast.NodeCloseBracket})
node.AppendChild(&ast.Node{Type: ast.NodeOpenBracket})
node.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(lute.domAttrValue(n, "link-label"))})
node.AppendChild(&ast.Node{Type: ast.NodeCloseBracket})
tree.Context.Tip.AppendChild(node)
}
return
case atom.Font:
Expand Down

0 comments on commit 0e1f2c6

Please sign in to comment.