Skip to content

Commit

Permalink
🎨 Vditor 支持
Browse files Browse the repository at this point in the history
When link with "" and ctrl+k
Fix Vanessa219/vditor#261
  • Loading branch information
88250 committed Apr 2, 2020
1 parent 0cd1684 commit 68743e5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 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.

22 changes: 19 additions & 3 deletions parse/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,25 @@ func (t *Tree) parseCloseBracket(ctx *InlineContext) *ast.Node {
matched = isLink && 0 < len(remains)
if matched {
if t.Context.Option.VditorWYSIWYG {
if bytes.HasPrefix(remains, []byte(Caret + ")")) {
remains = remains[len([]byte(Caret + ")")):]
remains = append([]byte(")" + Caret), remains...)
if bytes.HasPrefix(remains, []byte(Caret+")")) {
if 0 < len(title) {
// 将 ‸) 换位为 )‸
remains = remains[len([]byte(Caret+")")):]
remains = append([]byte(")"+Caret), remains...)
copy(ctx.tokens[ctx.pos-1:], remains) // 同时也将 tokens 换位,后续解析从光标位置开始
} else {
// 将 ""‸ 换位为 "‸"
title = []byte(Caret)
remains = remains[len([]byte(Caret)):]
ctx.pos += 3
}
} else if bytes.HasPrefix(remains, []byte(")"+Caret)) {
if 0 == len(title) {
// 将 "")‸ 换位为 "‸")
title = []byte(Caret)
remains = bytes.ReplaceAll(remains, []byte(Caret), nil)
ctx.pos += 3
}
}
}
matched = lex.ItemCloseParen == remains[0]
Expand Down
4 changes: 3 additions & 1 deletion test/spinv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ func TestSpinVditorDOM(t *testing.T) {

var spinVditorIRDOMTests = []*parseTest{

{"21", "<p data-block=\"0\">[foo](bar \"b\"<wbr>)\n</p>", ""},
{"23", "<p data-block=\"0\">[foo](bar \"\")<wbr>\n</p>", "<p data-block=\"0\"><span data-type=\"a\" class=\"vditor-ir__node vditor-ir__node--expand\"><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">[</span><span class=\"vditor-ir__link vditor-ir__marker--linktext\">foo</span><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">]</span><span class=\"vditor-ir__marker vditor-ir__marker--paren\">(</span><span class=\"vditor-ir__marker vditor-ir__marker--link\">bar</span> <span class=\"vditor-ir__marker vditor-ir__marker--title\">\"<wbr>\"</span><span class=\"vditor-ir__marker vditor-ir__marker--paren\">)</span></span>\n</p>"},
{"22", "<p data-block=\"0\">[foo](bar \"\"<wbr>)\n</p>", "<p data-block=\"0\"><span data-type=\"a\" class=\"vditor-ir__node vditor-ir__node--expand\"><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">[</span><span class=\"vditor-ir__link vditor-ir__marker--linktext\">foo</span><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">]</span><span class=\"vditor-ir__marker vditor-ir__marker--paren\">(</span><span class=\"vditor-ir__marker vditor-ir__marker--link\">bar</span> <span class=\"vditor-ir__marker vditor-ir__marker--title\">\"<wbr>\"</span><span class=\"vditor-ir__marker vditor-ir__marker--paren\">)</span></span>\n</p>"},
{"21", "<p data-block=\"0\">[foo](bar \"b\"<wbr>)\n</p>", "<p data-block=\"0\"><span data-type=\"a\" class=\"vditor-ir__node vditor-ir__node--expand\"><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">[</span><span class=\"vditor-ir__link vditor-ir__marker--linktext\">foo</span><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">]</span><span class=\"vditor-ir__marker vditor-ir__marker--paren\">(</span><span class=\"vditor-ir__marker vditor-ir__marker--link\">bar</span> <span class=\"vditor-ir__marker vditor-ir__marker--title\">\"b\"</span><span class=\"vditor-ir__marker vditor-ir__marker--paren\">)</span></span><wbr>\n</p>"},
{"20", "<p data-block=\"0\"><span data-type=\"a\" class=\"vditor-ir__node\"><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">[</span><span class=\"vditor-ir__link vditor-ir__marker--linktext\">foo</span><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">]</span><span class=\"vditor-ir__marker vditor-ir__marker--paren\">(</span><span class=\"vditor-ir__marker vditor-ir__marker--link\">bar</span> <span class=\"vditor-ir__marker vditor-ir__marker--title\">\"b<wbr>\"</span><span class=\"vditor-ir__marker vditor-ir__marker--paren\">)</span></span>\n</p>", "<p data-block=\"0\"><span data-type=\"a\" class=\"vditor-ir__node vditor-ir__node--expand\"><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">[</span><span class=\"vditor-ir__link vditor-ir__marker--linktext\">foo</span><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">]</span><span class=\"vditor-ir__marker vditor-ir__marker--paren\">(</span><span class=\"vditor-ir__marker vditor-ir__marker--link\">bar</span> <span class=\"vditor-ir__marker vditor-ir__marker--title\">\"b<wbr>\"</span><span class=\"vditor-ir__marker vditor-ir__marker--paren\">)</span></span>\n</p>"},
{"19", "<p data-block=\"0\">&lt;foo<wbr>&gt;\n</p>", "<p data-block=\"0\"><span data-type=\"inline-node\" class=\"vditor-ir__node\"><code class=\"vditor-ir__marker\">&lt;foo<wbr>&gt;</code><span class=\"vditor-ir__preview\" data-render=\"1\"><foo></span></span>\n</p>"},
{"18", "<p data-block=\"0\">&lt;<wbr>\n</p>", "<p data-block=\"0\">&lt;<wbr>\n</p>"},
Expand Down

0 comments on commit 68743e5

Please sign in to comment.