Skip to content

Commit

Permalink
✨ 支持 kramdown 行级属性列表 #89
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Sep 13, 2020
1 parent f44aa16 commit 096f11b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
9 changes: 4 additions & 5 deletions parse/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,11 @@ var blockStarts = []blockStartFunc{

if ial := t.parseKramdownIAL(); nil != ial {
t.Context.closeUnmatchedBlocks()

if ast.NodeDocument == t.Context.Tip.Type {
t.Context.Tip.LastChild.KramdownIAL = ial // 挂到最后一个子块上
} else {
t.Context.Tip.KramdownIAL = ial // 挂到当前末梢上
lastMatchedContainer := t.Context.lastMatchedContainer
if t.Context.allClosed && (ast.NodeDocument == lastMatchedContainer.Type || ast.NodeListItem == lastMatchedContainer.Type) {
lastMatchedContainer = t.Context.Tip.LastChild // 挂到最后一个子块上
}
lastMatchedContainer.KramdownIAL = ial
t.Context.offset = t.Context.currentLineLen // 整行过
return 2
}
Expand Down
24 changes: 15 additions & 9 deletions test/kramdown_ial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ import (

var kramIALTests = []parseTest{

//{"8", "* foo\n\n > bar\n {: id=\"barid\"}\n{: id=\"id\"}", "<ul id=\"id\">\n<li>\n<p>foo</p>\n</li>\n<li>\n<p id=\"fooid\">foo</p>\n</li>\n</ul>\n"},
{"7", "* > foo\n {: id=\"fooid\"}\n{: id=\"id\"}", "<ul id=\"id\">\n<li>\n<p>foo</p>\n</li>\n<li>\n<p id=\"fooid\">foo</p>\n</li>\n</ul>\n"},
{"6", "* foo\n\n* foo\n {: id=\"fooid\"}\n{: id=\"id\"}", "<ul id=\"id\">\n<li>\n<p>foo</p>\n</li>\n<li>\n<p id=\"fooid\">foo</p>\n</li>\n</ul>\n"},
{"5", "* foo\n {: id=\"fooid\"}\n{: id=\"id\"}\n", "<ul id=\"id\">\n<li>foo</li>\n</ul>\n"},
{"4", "* foo\n{: id=\"fooid\"}\n", "<ul id=\"fooid\">\n<li>foo</li>\n</ul>\n"},
{"3", "> foo\n> {: id=\"fooid\"}\n>\n> baz\n> {: id=\"bazid\"}\n>\n{: id=\"bqid\"}\n", "<blockquote id=\"bqid\">\n<p id=\"fooid\">foo</p>\n<p id=\"bazid\">baz</p>\n</blockquote>\n"},
{"2", "> foo\n> {: id=\"fooid\"}\n{: id=\"bqid\"}\n", "<blockquote id=\"bqid\">\n<p id=\"fooid\">foo</p>\n</blockquote>\n"},
{"1", "> foo\n> {: id=\"fooid\" name=\"bar\"}\n", "<blockquote>\n<p id=\"fooid\" name=\"bar\">foo</p>\n</blockquote>\n"},
{"0", "foo\n{: id=\"fooid\" class=\"bar\"}\n", "<p id=\"fooid\" class=\"bar\">foo</p>\n"},
//{"14", "foo\n{: id=\"fooid\"}\nbar\n{: id=\"barid\"}", "<ul id=\"id\">\n<li>\n<p>foo</p>\n<blockquote id=\"bqid\">\n<p>bar</p>\n</blockquote>\n<blockquote>\n<p id=\"bazid\">baz</p>\n</blockquote>\n</li>\n<li>\n<p id=\"bazid\">baz</p>\n</li>\n</ul>\n"},
{"13", "foo\n{: id=\"fooid\"}\nbar", "<ul id=\"id\">\n<li>\n<p>foo</p>\n<blockquote id=\"bqid\">\n<p>bar</p>\n</blockquote>\n<blockquote>\n<p id=\"bazid\">baz</p>\n</blockquote>\n</li>\n<li>\n<p id=\"bazid\">baz</p>\n</li>\n</ul>\n"},
{"12", "* foo\n\n > bar\n {: id=\"bqid\"}\n > baz\n > {: id=\"bazid\"}\n* baz\n {: id=\"bazid\"}\n{: id=\"id\"}", "<ul id=\"id\">\n<li>\n<p>foo</p>\n<blockquote id=\"bqid\">\n<p>bar</p>\n</blockquote>\n<blockquote>\n<p id=\"bazid\">baz</p>\n</blockquote>\n</li>\n<li>\n<p id=\"bazid\">baz</p>\n</li>\n</ul>\n"},
{"11", "* foo\n * bar\n * baz\n {: id=\"subid\"}\n{: id=\"id\"}", "<ul id=\"id\">\n<li>foo\n<ul id=\"subid\">\n<li>bar</li>\n<li>baz</li>\n</ul>\n</li>\n</ul>\n"},
{"10", "* foo\n * bar\n * baz\n {: id=\"subid\"}\n{: id=\"id\"}", "<ul id=\"id\">\n<li>foo\n<ul id=\"subid\">\n<li>bar</li>\n<li>baz</li>\n</ul>\n</li>\n</ul>\n"},
{"9", "* foo\n\n > bar\n > {: id=\"barid\"}\n {: id=\"bqid\"}\n\n baz\n{: id=\"id\"}", "<ul id=\"id\">\n<li>\n<p>foo</p>\n<blockquote id=\"bqid\">\n<p id=\"barid\">bar</p>\n</blockquote>\n<p>baz</p>\n</li>\n</ul>\n"},
{"8", "* foo\n\n > bar\n {: id=\"bqid\"}\n{: id=\"id\"}", "<ul id=\"id\">\n<li>\n<p>foo</p>\n<blockquote id=\"bqid\">\n<p>bar</p>\n</blockquote>\n</li>\n</ul>\n"},
{"7", "* > foo\n {: id=\"bqid\"}\n{: id=\"id\"}", "<ul id=\"id\">\n<li>\n<blockquote id=\"bqid\">\n<p>foo</p>\n</blockquote>\n</li>\n</ul>\n"},
{"6", "* foo\n\n* bar\n {: id=\"barid\"}\n{: id=\"id\"}", "<ul id=\"id\">\n<li>\n<p>foo</p>\n</li>\n<li>\n<p id=\"barid\">bar</p>\n</li>\n</ul>\n"},
{"5", "* foo\n {: id=\"fooid\"}\n{: id=\"id\"}", "<ul id=\"id\">\n<li>foo</li>\n</ul>\n"},
{"4", "* foo\n{: id=\"fooid\"}", "<ul id=\"fooid\">\n<li>foo</li>\n</ul>\n"},
{"3", "> foo\n> {: id=\"fooid\"}\n>\n> baz\n> {: id=\"bazid\"}\n>\n{: id=\"bqid\"}", "<blockquote id=\"bqid\">\n<p id=\"fooid\">foo</p>\n<p id=\"bazid\">baz</p>\n</blockquote>\n"},
{"2", "> foo\n> {: id=\"fooid\"}\n{: id=\"bqid\"}", "<blockquote id=\"bqid\">\n<p id=\"fooid\">foo</p>\n</blockquote>\n"},
{"1", "> foo\n> {: id=\"fooid\" name=\"bar\"}", "<blockquote>\n<p id=\"fooid\" name=\"bar\">foo</p>\n</blockquote>\n"},
{"0", "foo\n{: id=\"fooid\" class=\"bar\"}", "<p id=\"fooid\" class=\"bar\">foo</p>\n"},
}

func TestKramIALs(t *testing.T) {
Expand Down

0 comments on commit 096f11b

Please sign in to comment.