Skip to content

Commit

Permalink
✨ 支持 kramdown 内联属性列表 #89
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Sep 15, 2020
1 parent c9623ab commit a0105e2
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 31 deletions.
2 changes: 1 addition & 1 deletion ast/node.go
Expand Up @@ -463,7 +463,7 @@ const (

// kramdown 内联属性列表 https://github.com/88250/lute/issues/89

NodeKramdownIAL NodeType = 455 // 内联属性列表 {: name="value"}
NodeKramdownBlockIAL NodeType = 455 // 块级内联属性列表 {: name="value"}

NodeTypeMaxVal NodeType = 1024 // 节点类型最大值
)
8 changes: 4 additions & 4 deletions ast/nodetype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 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.

2 changes: 1 addition & 1 deletion parse/blocks.go
Expand Up @@ -521,7 +521,7 @@ var blockStarts = []blockStartFunc{
}
lastMatchedContainer.KramdownIAL = ial
t.Context.offset = t.Context.currentLineLen // 整行过
node := t.Context.addChild(ast.NodeKramdownIAL, t.Context.nextNonspace)
node := t.Context.addChild(ast.NodeKramdownBlockIAL, t.Context.nextNonspace)
node.Tokens = t.Context.currentLine
return 2
}
Expand Down
7 changes: 4 additions & 3 deletions render/format_renderer.go
Expand Up @@ -118,16 +118,17 @@ func NewFormatRenderer(tree *parse.Tree) *FormatRenderer {
ret.RendererFuncs[ast.NodeMark1CloseMarker] = ret.renderMark1CloseMarker
ret.RendererFuncs[ast.NodeMark2OpenMarker] = ret.renderMark2OpenMarker
ret.RendererFuncs[ast.NodeMark2CloseMarker] = ret.renderMark2CloseMarker
ret.RendererFuncs[ast.NodeKramdownIAL] = ret.renderKramdownIAL
ret.RendererFuncs[ast.NodeKramdownBlockIAL] = ret.renderKramdownBlockIAL
return ret
}

func (r *FormatRenderer) renderKramdownIAL(node *ast.Node, entering bool) ast.WalkStatus {
func (r *FormatRenderer) renderKramdownBlockIAL(node *ast.Node, entering bool) ast.WalkStatus {
if entering {
r.Newline()
r.Write(node.Tokens)
} else {
r.Newline()
r.WriteByte(lex.ItemNewline)
}
return ast.WalkContinue
}
Expand Down Expand Up @@ -664,7 +665,7 @@ func (r *FormatRenderer) renderCodeBlockCloseMarker(node *ast.Node, entering boo
r.Write(node.Tokens)
r.Newline()
if !r.isLastNode(r.Tree.Root, node) {
if 0 == len(node.KramdownIAL) {
if 0 == len(node.Parent.KramdownIAL) {
r.WriteByte(lex.ItemNewline)
}
}
Expand Down
4 changes: 2 additions & 2 deletions render/html_renderer.go
Expand Up @@ -119,11 +119,11 @@ func NewHtmlRenderer(tree *parse.Tree) *HtmlRenderer {
ret.RendererFuncs[ast.NodeMark1CloseMarker] = ret.renderMark1CloseMarker
ret.RendererFuncs[ast.NodeMark2OpenMarker] = ret.renderMark2OpenMarker
ret.RendererFuncs[ast.NodeMark2CloseMarker] = ret.renderMark2CloseMarker
ret.RendererFuncs[ast.NodeKramdownIAL] = ret.renderKramdownIAL
ret.RendererFuncs[ast.NodeKramdownBlockIAL] = ret.renderKramdownBlockIAL
return ret
}

func (r *HtmlRenderer) renderKramdownIAL(node *ast.Node, entering bool) ast.WalkStatus {
func (r *HtmlRenderer) renderKramdownBlockIAL(node *ast.Node, entering bool) ast.WalkStatus {
return ast.WalkContinue
}

Expand Down
4 changes: 2 additions & 2 deletions render/vditor_ir_block_renderer.go
Expand Up @@ -117,7 +117,7 @@ func NewVditorIRBlockRenderer(tree *parse.Tree) *VditorIRBlockRenderer {
ret.RendererFuncs[ast.NodeMark1CloseMarker] = ret.renderMark1CloseMarker
ret.RendererFuncs[ast.NodeMark2OpenMarker] = ret.renderMark2OpenMarker
ret.RendererFuncs[ast.NodeMark2CloseMarker] = ret.renderMark2CloseMarker
ret.RendererFuncs[ast.NodeKramdownIAL] = ret.renderKramdownIAL
ret.RendererFuncs[ast.NodeKramdownBlockIAL] = ret.renderKramdownBlockIAL
return ret
}

Expand All @@ -144,7 +144,7 @@ func (r *VditorIRBlockRenderer) Render() (output []byte) {
return
}

func (r *VditorIRBlockRenderer) renderKramdownIAL(node *ast.Node, entering bool) ast.WalkStatus {
func (r *VditorIRBlockRenderer) renderKramdownBlockIAL(node *ast.Node, entering bool) ast.WalkStatus {
return ast.WalkContinue
}

Expand Down
4 changes: 2 additions & 2 deletions render/vditor_ir_renderer.go
Expand Up @@ -114,7 +114,7 @@ func NewVditorIRRenderer(tree *parse.Tree) *VditorIRRenderer {
ret.RendererFuncs[ast.NodeMark1CloseMarker] = ret.renderMark1CloseMarker
ret.RendererFuncs[ast.NodeMark2OpenMarker] = ret.renderMark2OpenMarker
ret.RendererFuncs[ast.NodeMark2CloseMarker] = ret.renderMark2CloseMarker
ret.RendererFuncs[ast.NodeKramdownIAL] = ret.renderKramdownIAL
ret.RendererFuncs[ast.NodeKramdownBlockIAL] = ret.renderKramdownBlockIAL
return ret
}

Expand All @@ -141,7 +141,7 @@ func (r *VditorIRRenderer) Render() (output []byte) {
return
}

func (r *VditorIRRenderer) renderKramdownIAL(node *ast.Node, entering bool) ast.WalkStatus {
func (r *VditorIRRenderer) renderKramdownBlockIAL(node *ast.Node, entering bool) ast.WalkStatus {
if entering {
r.tag("span", [][]string{{"data-type", "kramdown-ial"}}, false)
r.Write(node.Tokens)
Expand Down
4 changes: 2 additions & 2 deletions render/vditor_sv_renderer.go
Expand Up @@ -153,7 +153,7 @@ func NewVditorSVRenderer(tree *parse.Tree) *VditorSVRenderer {
ret.RendererFuncs[ast.NodeMark1CloseMarker] = ret.renderMark1CloseMarker
ret.RendererFuncs[ast.NodeMark2OpenMarker] = ret.renderMark2OpenMarker
ret.RendererFuncs[ast.NodeMark2CloseMarker] = ret.renderMark2CloseMarker
ret.RendererFuncs[ast.NodeKramdownIAL] = ret.renderKramdownIAL
ret.RendererFuncs[ast.NodeKramdownBlockIAL] = ret.renderKramdownBlockIAL
return ret
}

Expand Down Expand Up @@ -191,7 +191,7 @@ func (r *VditorSVRenderer) Render() (output []byte) {
return
}

func (r *VditorSVRenderer) renderKramdownIAL(node *ast.Node, entering bool) ast.WalkStatus {
func (r *VditorSVRenderer) renderKramdownBlockIAL(node *ast.Node, entering bool) ast.WalkStatus {
if entering {
r.Newline()
r.tag("span", [][]string{{"data-type", "kramdown-ial"}, {"class", "vditor-sv__marker"}}, false)
Expand Down
4 changes: 2 additions & 2 deletions render/vditor_wysiwyg_renderer.go
Expand Up @@ -116,7 +116,7 @@ func NewVditorRenderer(tree *parse.Tree) *VditorRenderer {
ret.RendererFuncs[ast.NodeMark1CloseMarker] = ret.renderMark1CloseMarker
ret.RendererFuncs[ast.NodeMark2OpenMarker] = ret.renderMark2OpenMarker
ret.RendererFuncs[ast.NodeMark2CloseMarker] = ret.renderMark2CloseMarker
ret.RendererFuncs[ast.NodeKramdownIAL] = ret.renderKramdownIAL
ret.RendererFuncs[ast.NodeKramdownBlockIAL] = ret.renderKramdownBlockIAL
return ret
}

Expand All @@ -143,7 +143,7 @@ func (r *VditorRenderer) Render() (output []byte) {
return
}

func (r *VditorRenderer) renderKramdownIAL(node *ast.Node, entering bool) ast.WalkStatus {
func (r *VditorRenderer) renderKramdownBlockIAL(node *ast.Node, entering bool) ast.WalkStatus {
return ast.WalkContinue
}

Expand Down
1 change: 1 addition & 0 deletions test/v2m_test.go
Expand Up @@ -180,6 +180,7 @@ var vditorIRBlockDOM2MdTests = []parseTest{

func TestVditorIRBlockDOM2Md(t *testing.T) {
luteEngine := lute.New()
luteEngine.KramdownIAL = true

for _, test := range vditorIRBlockDOM2MdTests {
md := luteEngine.VditorIRBlockDOM2Md(test.from)
Expand Down
11 changes: 3 additions & 8 deletions vditor_ir_block.go
Expand Up @@ -253,14 +253,9 @@ func (lute *Lute) genASTByVditorIRBlockDOM(n *html.Node, tree *parse.Tree) {
}
}
if "" != nodeID {
text := lute.domText(n)
text = strings.ReplaceAll(text, parse.Zwsp, "")
text = strings.TrimSpace(text)
if "" != text {
node.KramdownIAL = [][]string{{"id", nodeID}}
ial := &ast.Node{Type: ast.NodeKramdownIAL, Tokens: []byte("{: id=\"" + nodeID + "\"}")}
defer tree.Context.Tip.AppendChild(ial)
}
node.KramdownIAL = [][]string{{"id", nodeID}}
ial := &ast.Node{Type: ast.NodeKramdownBlockIAL, Tokens: []byte("{: id=\"" + nodeID + "\"}")}
defer tree.Context.Tip.AppendChild(ial)
}

switch n.DataAtom {
Expand Down

0 comments on commit a0105e2

Please sign in to comment.