Skip to content

Commit

Permalink
✨ 支持 kramdown 内联属性列表 #89
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Sep 14, 2020
1 parent 506ef4d commit 36e7f88
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 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.

12 changes: 4 additions & 8 deletions render/vditor_ir_block_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ func (r *VditorIRBlockRenderer) Render() (output []byte) {
}

func (r *VditorIRBlockRenderer) renderKramdownIAL(node *ast.Node, entering bool) ast.WalkStatus {
if entering {
r.tag("span", [][]string{{"data-type", "kramdown-ial"}}, false)
r.Write(node.Tokens)
r.tag("/span", nil, false)
}
return ast.WalkContinue
}

Expand Down Expand Up @@ -989,7 +984,7 @@ func (r *VditorIRBlockRenderer) renderParagraph(node *ast.Node, entering bool) a
}

if entering {
r.tag("p", [][]string{{"data-block", "0"}, {"data-node-id", r.NodeID(node)}}, false)
r.tag("p", [][]string{{"data-block", "0"}, {"data-node-id", r.NodeID(node)}, {"data-type", "p"}}, false)
} else {
r.tag("/p", nil, false)
}
Expand Down Expand Up @@ -1136,7 +1131,7 @@ func (r *VditorIRBlockRenderer) renderStrongU8eCloseMarker(node *ast.Node, enter

func (r *VditorIRBlockRenderer) renderBlockquote(node *ast.Node, entering bool) ast.WalkStatus {
if entering {
r.WriteString(`<blockquote data-block="0" data-node-id="` + r.NodeID(node) + `">`)
r.tag("blockquote", [][]string{{"data-block", "0"}, {"data-node-id", r.NodeID(node)}, {"data-type", "blockquote"}}, false)
} else {
r.WriteString("</blockquote>")
}
Expand All @@ -1158,7 +1153,7 @@ func (r *VditorIRBlockRenderer) renderHeading(node *ast.Node, entering bool) ast
r.WriteString("<h" + level + " data-block=\"0\" class=\"vditor-ir__node\"")
}

r.WriteString(" data-node-id=\"" + r.NodeID(node) + "\"")
r.WriteString(" data-node-id=\"" + r.NodeID(node) + "\" data-type=\"h\"")

var id string
if nil != headingID {
Expand Down Expand Up @@ -1247,6 +1242,7 @@ func (r *VditorIRBlockRenderer) renderList(node *ast.Node, entering bool) ast.Wa
}
attrs = append(attrs, []string{"data-block", "0"})
attrs = append(attrs, []string{"data-node-id", r.NodeID(node)})
attrs = append(attrs, []string{"data-type", tag})
r.renderListStyle(node, &attrs)
r.tag(tag, attrs, false)
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/m2v_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestMd2VditorIR(t *testing.T) {

var md2VditorIRBlockTests = []parseTest{

{"1", "foo\n{: id=\"fooid\"}\nbar\n{: id=\"barid\"}", "<p data-block=\"0\" data-node-id=\"fooid\">foo</p><span data-type=\"kramdown-ial\">{: id=\"fooid\"}\n</span><p data-block=\"0\" data-node-id=\"barid\">bar</p><span data-type=\"kramdown-ial\">{: id=\"barid\"}\n</span>"},
{"1", "foo\n{: id=\"fooid\"}\nbar\n{: id=\"barid\"}", "<p data-block=\"0\" data-node-id=\"fooid\" data-type=\"p\">foo</p><p data-block=\"0\" data-node-id=\"barid\" data-type=\"p\">bar</p>"},
{"0", "", ""},
}

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

var spinVditorIRBlockDOMTests = []*parseTest{

{"0", "<p data-block=\"0\" data-node-id=\"fooid\">foo</p>\n<p data-block=\"0\" data-node-id=\"barid\">bar</p>", "<p data-block=\"0\" data-node-id=\"fooid\">foo</p><span data-type=\"kramdown-ial\">{: id=\"fooid\"}\n</span><p data-block=\"0\" data-node-id=\"barid\">bar</p><span data-type=\"kramdown-ial\">{: id=\"barid\"}\n</span>"},
{"0", "<p data-block=\"0\" data-node-id=\"20200914181352-laa3jyd\" data-type=\"p\">foo<wbr></p>", "<p data-block=\"0\" data-node-id=\"20200914181352-laa3jyd\" data-type=\"p\">foo<wbr></p>"},
}

func TestSpinVditorIRBlockDOM(t *testing.T) {
Expand Down
11 changes: 8 additions & 3 deletions vditor_ir_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ func (lute *Lute) genASTByVditorIRBlockDOM(n *html.Node, tree *parse.Tree) {
}

dataType := lute.domAttrValue(n, "data-type")
nodeID := lute.domAttrValue(n, "data-node-id")

if atom.Div == n.DataAtom {
// TODO: 细化节点 /~https://github.com/88250/liandi/issues/163
Expand Down Expand Up @@ -245,10 +244,16 @@ func (lute *Lute) genASTByVditorIRBlockDOM(n *html.Node, tree *parse.Tree) {

class := lute.domAttrValue(n, "class")
content := strings.ReplaceAll(n.Data, parse.Zwsp, "")
nodeID := lute.domAttrValue(n, "data-node-id")
node := &ast.Node{ID: nodeID, Type: ast.NodeText, Tokens: []byte(content)}

if "" == nodeID {
if "p" == dataType || "ul" == dataType || "ol" == dataType || "blockquote" == dataType ||
"math-block" == dataType || "code-block" == dataType || "table" == dataType || "h" == dataType {
nodeID = ast.NewNodeID()
}
}
if "" != nodeID {
node.KramdownIAL = [][]string{{"id", nodeID}} // TODO: 其他属性
node.KramdownIAL = [][]string{{"id", nodeID}}
ial := &ast.Node{Type: ast.NodeKramdownIAL, Tokens: []byte("{: id=\"" + nodeID + "\"}")}
defer tree.Context.Tip.AppendChild(ial)
}
Expand Down

0 comments on commit 36e7f88

Please sign in to comment.