Skip to content

Commit

Permalink
🎨 Vditor 支持
Browse files Browse the repository at this point in the history
Inline HTML parsing issue
Fix Vanessa219/vditor#303
  • Loading branch information
88250 committed Apr 11, 2020
1 parent 6284590 commit 91e3a9c
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 19 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.

8 changes: 0 additions & 8 deletions render/vditor_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,18 +539,10 @@ func (r *VditorRenderer) renderInlineHTML(node *ast.Node, entering bool) ast.Wal
node.Tokens = bytes.TrimSpace(node.Tokens)
r.tag("code", [][]string{{"data-type", "html-inline"}}, false)
tokens := bytes.ReplaceAll(node.Tokens, []byte(parse.Zwsp), nil)
previewTokens := tokens
tokens = util.EscapeHTML(tokens)
tokens = append([]byte(parse.Zwsp), tokens...)
r.Write(tokens)
r.WriteString("</code>")

r.tag("span", [][]string{{"class", "vditor-wysiwyg__preview"}, {"data-render", "1"}}, false)
r.WriteString(" ")
previewTokens = bytes.ReplaceAll(previewTokens, []byte(parse.Caret), nil)
previewTokens = sanitize(previewTokens)
r.Write(previewTokens)
r.tag("/span", nil, false)
r.WriteString("</span>" + parse.Zwsp)
return ast.WalkStop
}
Expand Down
5 changes: 0 additions & 5 deletions render/vditorir_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,11 +641,6 @@ func (r *VditorIRRenderer) renderInlineHTML(node *ast.Node, entering bool) ast.W
r.tag("code", [][]string{{"class", "vditor-ir__marker"}}, false)
r.Write(util.EscapeHTML(node.Tokens))
r.tag("/code", nil, false)
r.tag("span", [][]string{{"class", "vditor-ir__preview"}, {"data-render", "1"}}, false)
tokens := bytes.ReplaceAll(node.Tokens, []byte(parse.Caret), nil)
tokens = sanitize(tokens)
r.Write(tokens)
r.tag("/span", nil, false)
r.tag("/span", nil, false)
return ast.WalkStop
}
Expand Down
2 changes: 1 addition & 1 deletion test/m2v_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var md2VditorIRTests = []parseTest{

{"8", "`foo`", "<p data-block=\"0\"><span data-type=\"code\" class=\"vditor-ir__node\"><span class=\"vditor-ir__marker\">`</span><code data-newline=\"1\">foo</code><span class=\"vditor-ir__marker\">`</span></span>\n</p>"},
{"7", "$$\nfoo\n$$", "<div data-block=\"0\" data-type=\"math-block\" class=\"vditor-ir__node\"><span data-type=\"math-block-open-marker\">$$</span><pre class=\"vditor-ir__marker--pre vditor-ir__marker\"><code data-type=\"math-block\" class=\"language-math\">foo</code></pre><pre class=\"vditor-ir__preview\" data-render=\"2\"><code data-type=\"math-block\" class=\"language-math\">foo</code></pre><span data-type=\"math-block-close-marker\">$$</span></div>"},
{"6", "foo<bar>baz", "<p data-block=\"0\">foo<span data-type=\"inline-node\" class=\"vditor-ir__node\"><code class=\"vditor-ir__marker\">&lt;bar&gt;</code><span class=\"vditor-ir__preview\" data-render=\"1\"><bar></span></span>baz\n</p>"},
{"6", "foo<bar>baz", "<p data-block=\"0\">foo<span data-type=\"inline-node\" class=\"vditor-ir__node\"><code class=\"vditor-ir__marker\">&lt;bar&gt;</code></span>baz\n</p>"},
{"5", "$foo$", "<p data-block=\"0\"><span data-type=\"inline-node\" class=\"vditor-ir__node\"><span class=\"vditor-ir__marker\">$</span><code data-newline=\"1\" class=\"vditor-ir__marker vditor-ir__marker--pre\">foo</code><span class=\"vditor-ir__preview\" data-render=\"2\"><code class=\"language-math\">foo</code></span><span class=\"vditor-ir__marker\">$</span></span>\n</p>"},
{"4", "```foo\nbar\n```", "<div data-block=\"0\" data-type=\"code-block\" class=\"vditor-ir__node\"><span data-type=\"code-block-open-marker\">```</span><span class=\"vditor-ir__marker vditor-ir__marker--info\" data-type=\"code-block-info\">\u200bfoo</span><pre class=\"vditor-ir__marker--pre vditor-ir__marker\"><code class=\"language-foo\">bar\n</code></pre><pre class=\"vditor-ir__preview\" data-render=\"2\"><code class=\"language-foo\">bar\n</code></pre><span data-type=\"code-block-close-marker\">```</span></div>"},
{"3", "__foo__", "<p data-block=\"0\"><span data-type=\"strong\" class=\"vditor-ir__node\"><span class=\"vditor-ir__marker vditor-ir__marker--bi\">__</span><strong data-newline=\"1\">foo</strong><span class=\"vditor-ir__marker vditor-ir__marker--bi\">__</span></span>\n</p>"},
Expand Down
6 changes: 3 additions & 3 deletions test/spinv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,16 @@ var spinVditorIRDOMTests = []*parseTest{
{"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\">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\">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\">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\">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>"},
{"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>\n</p>"},
{"18", "<p data-block=\"0\">&lt;<wbr>\n</p>", "<p data-block=\"0\">&lt;<wbr>\n</p>"},
{"17", "<p data-block=\"0\">&lt;fo<wbr>o&gt;\n</p>", "<p data-block=\"0\"><span data-type=\"inline-node\" class=\"vditor-ir__node\"><code class=\"vditor-ir__marker\">&lt;fo<wbr>o&gt;</code><span class=\"vditor-ir__preview\" data-render=\"1\"><foo></span></span>\n</p>"},
{"17", "<p data-block=\"0\">&lt;fo<wbr>o&gt;\n</p>", "<p data-block=\"0\"><span data-type=\"inline-node\" class=\"vditor-ir__node\"><code class=\"vditor-ir__marker\">&lt;fo<wbr>o&gt;</code></span>\n</p>"},
{"16", "<p data-block=\"0\">**<wbr>**</p>", "<p data-block=\"0\"><span data-type=\"strong\" class=\"vditor-ir__node vditor-ir__node--expand\"><span class=\"vditor-ir__marker vditor-ir__marker--bi\">**</span><strong data-newline=\"1\"><wbr></strong><span class=\"vditor-ir__marker vditor-ir__marker--bi\">**</span></span>\n</p>"},
{"15", "<h1 data-block=\"0\" class=\"vditor-ir__node\" data-marker=\"#\"><span class=\"vditor-ir__marker vditor-ir__marker--heading\" data-type=\"heading-marker\"># </span>foo</h1><div><wbr><br></div>", "<h1 data-block=\"0\" class=\"vditor-ir__node\" data-marker=\"#\"><span class=\"vditor-ir__marker vditor-ir__marker--heading\" data-type=\"heading-marker\"># </span>foo</h1><p data-block=\"0\"><wbr>\n</p>"},
{"14", "<h1 data-block=\"0\" class=\"vditor-ir__node\" data-marker=\"#\"><span class=\"vditor-ir__marker vditor-ir__marker--heading\" data-type=\"heading-marker\" >#<wbr># </span>f</h1>", "<h2 data-block=\"0\" class=\"vditor-ir__node vditor-ir__node--expand\" data-marker=\"#\"><span class=\"vditor-ir__marker vditor-ir__marker--heading\" data-type=\"heading-marker\">## </span><wbr>f</h2>"},
{"13", "<p data-block=\"0\">#<wbr> f\n</p>", "<h1 data-block=\"0\" class=\"vditor-ir__node vditor-ir__node--expand\" data-marker=\"#\"><span class=\"vditor-ir__marker vditor-ir__marker--heading\" data-type=\"heading-marker\"># </span><wbr>f</h1>"},
{"12", "<p data-block=\"0\"><span data-type=\"inline-node\" class=\"vditor-ir__node\"><span class=\"vditor-ir__marker\">$</span><code data-newline=\"1\" class=\"vditor-ir__marker--pre vditor-ir__marker\">ab<wbr></code><span class=\"vditor-ir__preview\" data-render=\"1\"><code class=\"language-math\"><span class=\"vditor-math\" data-math=\"ab\"><span class=\"katex\"><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\"></span><span class=\"mord mathdefault\">a</span><span class=\"mord mathdefault\">b</span></span></span></span></span></code></span><span class=\"vditor-ir__marker\">$</span></span>\n</p>", "<p data-block=\"0\"><span data-type=\"inline-node\" class=\"vditor-ir__node vditor-ir__node--expand\"><span class=\"vditor-ir__marker\">$</span><code data-newline=\"1\" class=\"vditor-ir__marker vditor-ir__marker--pre\">ab<wbr></code><span class=\"vditor-ir__preview\" data-render=\"2\"><code class=\"language-math\">ab<wbr></code></span><span class=\"vditor-ir__marker\">$</span></span>\n</p>"},
{"11", "<div data-block=\"0\" data-type=\"math-block\" class=\"vditor-ir__node\"><span data-type=\"math-block-open-marker\">$$</span><pre class=\"vditor-ir__marker--pre vditor-ir__marker\"><code data-type=\"math-block\">foo</code></pre><pre class=\"vditor-ir__preview\" data-render=\"1\"><code data-type=\"math-block\">foo\n</code></pre><span data-type=\"math-block-close-marker\">$$</span></div>", "<div data-block=\"0\" data-type=\"math-block\" class=\"vditor-ir__node\"><span data-type=\"math-block-open-marker\">$$</span><pre class=\"vditor-ir__marker--pre vditor-ir__marker\"><code data-type=\"math-block\" class=\"language-math\">foo</code></pre><pre class=\"vditor-ir__preview\" data-render=\"2\"><code data-type=\"math-block\" class=\"language-math\">foo</code></pre><span data-type=\"math-block-close-marker\">$$</span></div>"},
{"10", "<p data-block=\"0\">foo<span data-type=\"inline-node\" class=\"vditor-ir__node\"><code class=\"vditor-ir__marker\">&lt;bar&gt;</code><span class=\"vditor-ir__preview\" data-render=\"1\"><bar></span></span>baz<wbr>\n</p>", "<p data-block=\"0\">foo<span data-type=\"inline-node\" class=\"vditor-ir__node\"><code class=\"vditor-ir__marker\">&lt;bar&gt;</code><span class=\"vditor-ir__preview\" data-render=\"1\"><bar></span></span>baz<wbr>\n</p>"},
{"10", "<p data-block=\"0\">foo<span data-type=\"inline-node\" class=\"vditor-ir__node\"><code class=\"vditor-ir__marker\">&lt;bar&gt;</code><span class=\"vditor-ir__preview\" data-render=\"1\"><bar></span></span>baz<wbr>\n</p>", "<p data-block=\"0\">foo<span data-type=\"inline-node\" class=\"vditor-ir__node\"><code class=\"vditor-ir__marker\">&lt;bar&gt;</code></span>baz<wbr>\n</p>"},
{"9", "<p data-block=\"0\"><span data-type=\"inline-node\" class=\"vditor-ir__node\"><span class=\"vditor-ir__marker\">$</span><code data-newline=\"1\">foo</code><span class=\"vditor-ir__marker\">$</span></span>\n</p>", "<p data-block=\"0\"><span data-type=\"inline-node\" class=\"vditor-ir__node\"><span class=\"vditor-ir__marker\">$</span><code data-newline=\"1\" class=\"vditor-ir__marker vditor-ir__marker--pre\">foo</code><span class=\"vditor-ir__preview\" data-render=\"2\"><code class=\"language-math\">foo</code></span><span class=\"vditor-ir__marker\">$</span></span>\n</p>"},
{"8", "<div data-block=\"0\" data-type=\"code-block\" class=\"vditor-ir__node\"><span data-type=\"code-block-open-marker\">```</span><span class=\"vditor-ir__marker vditor-ir__marker--info\" data-type=\"code-block-info\">​java</span><pre class=\"vditor-ir__marker--pre vditor-ir__marker\"><code class=\"language-java\">foo<wbr>\n</code></pre><span data-type=\"code-block-close-marker\">```</span></div>", "<div data-block=\"0\" data-type=\"code-block\" class=\"vditor-ir__node vditor-ir__node--expand\"><span data-type=\"code-block-open-marker\">```</span><span class=\"vditor-ir__marker vditor-ir__marker--info\" data-type=\"code-block-info\">\u200bjava</span><pre class=\"vditor-ir__marker--pre vditor-ir__marker\"><code class=\"language-java\">foo<wbr>\n</code></pre><pre class=\"vditor-ir__preview\" data-render=\"2\"><code class=\"language-java\">foo\n</code></pre><span data-type=\"code-block-close-marker\">```</span></div>"},
{"7", "<div data-block=\"0\" data-type=\"code-block\" class=\"vditor-ir__node\"><span class=\"vditor-ir__marker\" data-type=\"code-block-open-marker\">```<wbr></span><pre><code class=\"language-j\">foo\n</code></pre><span class=\"vditor-ir__marker\" data-type=\"code-block-close-marker\">```</span></div>", "<div data-block=\"0\" data-type=\"code-block\" class=\"vditor-ir__node vditor-ir__node--expand\"><span data-type=\"code-block-open-marker\">```</span><span class=\"vditor-ir__marker vditor-ir__marker--info\" data-type=\"code-block-info\">\u200b<wbr></span><pre class=\"vditor-ir__marker--pre vditor-ir__marker\"><code>foo\n</code></pre><pre class=\"vditor-ir__preview\" data-render=\"2\"><code>foo\n</code></pre><span data-type=\"code-block-close-marker\">```</span></div>"},
Expand Down

0 comments on commit 91e3a9c

Please sign in to comment.