Skip to content

Commit

Permalink
🎨 Vditor 支持
Browse files Browse the repository at this point in the history
task list 合并会添加 p 标签
Fix Vanessa219/vditor#435
  • Loading branch information
88250 committed May 24, 2020
1 parent bb6887d commit 1b2530e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 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 @@ -18,6 +18,7 @@ import (

var spinVditorDOMTests = []*parseTest{

{"120", "<ul data-tight=\"true\" data-marker=\"*\" data-block=\"0\"><li data-marker=\"*\" class=\"vditor-task\"><input type=\"checkbox\"> test<wbr></li></ul><ul data-tight=\"true\" data-marker=\"*\" data-block=\"0\"><li data-marker=\"*\" class=\"vditor-task\"><input type=\"checkbox\"> test</li></ul>", "<ul data-tight=\"true\" data-marker=\"*\" data-block=\"0\"><li data-marker=\"*\" class=\"vditor-task\"><input type=\"checkbox\" /> test<wbr></li><li data-marker=\"*\" class=\"vditor-task\"><input type=\"checkbox\" /> test</li></ul>"},
{"119", "&parx", "<p data-block=\"0\">&amp;parx\n</p>"},
{"118", "<ul data-tight=\"true\" data-marker=\"-\" data-block=\"0\"><li data-marker=\"-\"><p>[ ]<wbr></p></li></ul>", "<ul data-tight=\"true\" data-marker=\"-\" data-block=\"0\"><li data-marker=\"-\" class=\"vditor-task\"><input type=\"checkbox\" /> <wbr></li></ul>"},
{"117", "<p data-block=\"0\">foo<wbr><a>​</a></p>", "<p data-block=\"0\">foo<wbr>\n</p>"},
Expand Down
2 changes: 1 addition & 1 deletion test/v2m_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ var vditorIRDOM2MdTests = []parseTest{
{"7", "<span class=\"vditor-ir__marker vditor-ir__marker--bi\">*</span><em data-newline=\"1\">foo</em><span class=\"vditor-ir__marker vditor-ir__marker--bi\">*</span>", "*foo*\n"},
{"6", "<span class=\"vditor-ir__marker\">`</span><code data-newline=\"1\">foo</code><span class=\"vditor-ir__marker\">`</span>", "`foo`\n"},
{"5", "<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>", "`foo`\n"},
{"4", "<ul data-tight=\"true\" data-marker=\"+\" data-block=\"0\"><li data-marker=\"+\">foo</li></ul><ul data-tight=\"true\" data-marker=\"-\" data-block=\"0\"><li data-marker=\"-\">bar<ul data-tight=\"true\" data-marker=\"-\" data-block=\"0\"><li data-marker=\"-\">b<wbr></li></ul></li></ul>", "+ foo\n\n- bar\n - b\n"},
{"4", "<ul data-tight=\"true\" data-marker=\"+\" data-block=\"0\"><li data-marker=\"+\">foo</li></ul><ul data-tight=\"true\" data-marker=\"-\" data-block=\"0\"><li data-marker=\"-\">bar<ul data-tight=\"true\" data-marker=\"-\" data-block=\"0\"><li data-marker=\"-\">b<wbr></li></ul></li></ul>", "+ foo\n- bar\n - b\n"},
{"3", "<ul data-tight=\"true\" data-marker=\"*\" data-block=\"0\"><li data-marker=\"*\"><span data-type=\"inline-node\" class=\"vditor-ir__node\"><span class=\"vditor-ir__marker vditor-ir__marker--bi\">*</span><em data-newline=\"1\">foo</em><span class=\"vditor-ir__marker vditor-ir__marker--bi\">*</span></span>ba<wbr></li></ul>", "* *foo*ba\n"},
{"2", "<ul data-tight=\"true\" data-marker=\"*\" data-block=\"0\"><li data-marker=\"*\">foo<ul data-tight=\"true\" data-marker=\"*\" data-block=\"0\"><li data-marker=\"*\">bar</li></ul></li></ul>", "* foo\n * bar\n"},
{"1", "<h1 data-block=\"0\" class=\"vditor-ir__node\" data-marker=\"#\"><span class=\"vditor-ir__marker\" data-type=\"heading-marker\"># </span>foo</h1>", "# foo\n"},
Expand Down
18 changes: 13 additions & 5 deletions vditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,17 @@ func (lute *Lute) vditorDOM2Md(htmlStr string) (markdown string) {
}

func (lute *Lute) adjustVditorDOM(nodes []*html.Node) {
for _, n := range nodes {
for c := n; nil != c; c = c.NextSibling {
lute.adjustVditorDOM0(c)
if 1 < len(nodes) {
i := 0
for j := 1; j < len(nodes); j++ {
nodes[i].InsertAfter(nodes[j])
i++
}
}

for c := nodes[0]; nil != c; c = c.NextSibling {
lute.adjustVditorDOM0(c)
}
}

func (lute *Lute) adjustVditorDOM0(n *html.Node) {
Expand Down Expand Up @@ -241,7 +247,8 @@ func (lute *Lute) adjustVditorDOM0(n *html.Node) {
// 合并邻接的 ul

if nil != n.NextSibling && atom.Ul == n.NextSibling.DataAtom {
if nextTight := lute.domAttrValue(n.NextSibling, "data-tight"); "" == nextTight {
tight := lute.domAttrValue(n, "data-tight")
if nextTight := lute.domAttrValue(n.NextSibling, "data-tight"); "" == nextTight || tight == nextTight {
for c := n.NextSibling.FirstChild; nil != c; c = c.NextSibling {
c.Unlink()
n.AppendChild(c)
Expand All @@ -252,7 +259,8 @@ func (lute *Lute) adjustVditorDOM0(n *html.Node) {
// 合并邻接的 ol

if nil != n.NextSibling && atom.Ol == n.NextSibling.DataAtom {
if nextTight := lute.domAttrValue(n.NextSibling, "data-tight"); "" == nextTight {
tight := lute.domAttrValue(n, "data-tight")
if nextTight := lute.domAttrValue(n.NextSibling, "data-tight"); "" == nextTight || tight == nextTight {
for c := n.NextSibling.FirstChild; nil != c; c = c.NextSibling {
c.Unlink()
n.AppendChild(c)
Expand Down

0 comments on commit 1b2530e

Please sign in to comment.