Skip to content

Commit

Permalink
🐛 kramdown IAL HTML 块解析异常
Browse files Browse the repository at this point in the history
优化排版导致无法删除 HTML 块 siyuan-note/siyuan#6311
  • Loading branch information
88250 committed Oct 22, 2022
1 parent 0b40585 commit 92ba7f9
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 3 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.

3 changes: 2 additions & 1 deletion parse/html_block.go
Expand Up @@ -73,8 +73,8 @@ func HtmlBlockContinue(html *ast.Node, context *Context) int {
if context.ParseOption.KramdownBlockIAL && simpleCheckIsBlockIAL(tokens) {
// 判断 IAL 打断
if ial := context.parseKramdownBlockIAL(tokens); 0 < len(ial) {
context.Tip.ID = IAL2Map(ial)["id"]
context.Tip.KramdownIAL = ial
context.Tip.InsertAfter(&ast.Node{Type: ast.NodeKramdownBlockIAL, Tokens: tokens})
return 1
}
}
Expand Down Expand Up @@ -105,6 +105,7 @@ func (t *Tree) isHTMLBlockClose(tokens []byte, htmlType int) bool {
if t.Context.ParseOption.KramdownBlockIAL && simpleCheckIsBlockIAL(tokens) {
// 判断 IAL 打断
if ial := t.Context.parseKramdownBlockIAL(tokens); 0 < len(ial) {
t.Context.Tip.ID = IAL2Map(ial)["id"]
t.Context.Tip.KramdownIAL = ial
t.Context.Tip.InsertAfter(&ast.Node{Type: ast.NodeKramdownBlockIAL, Tokens: tokens})
return true
Expand Down
1 change: 1 addition & 0 deletions parse/math_block.go
Expand Up @@ -118,6 +118,7 @@ func (context *Context) isMathBlockClose(tokens []byte) bool {
if context.ParseOption.KramdownBlockIAL && simpleCheckIsBlockIAL(tokens) {
// 判断 IAL 打断
if ial := context.parseKramdownBlockIAL(tokens); 0 < len(ial) {
context.Tip.ID = IAL2Map(ial)["id"]
context.Tip.KramdownIAL = ial
context.Tip.InsertAfter(&ast.Node{Type: ast.NodeKramdownBlockIAL, Tokens: tokens})
return true
Expand Down
1 change: 1 addition & 0 deletions parse/yaml_front_matter.go
Expand Up @@ -83,6 +83,7 @@ func isYamlFrontMatterClose(context *Context) bool {
if context.ParseOption.KramdownBlockIAL && simpleCheckIsBlockIAL(context.currentLine) {
// 判断 IAL 打断
if ial := context.parseKramdownBlockIAL(context.currentLine); 0 < len(ial) {
context.Tip.ID = IAL2Map(ial)["id"]
context.Tip.KramdownIAL = ial
context.Tip.InsertAfter(&ast.Node{Type: ast.NodeKramdownBlockIAL, Tokens: context.currentLine})
return true
Expand Down
1 change: 1 addition & 0 deletions test/kramdown_block_ial_test.go
Expand Up @@ -19,6 +19,7 @@ import (

var kramdownBlockIALTests = []parseTest{

{"25", "<div>\n<details>\n<summary>foo</summary>\n</div>\n{: id=\"20221022222200-2b6wj74\" updated=\"20221022222200\"}\n", "<div>\n<details>\n<summary>foo</summary>\n</div>\n"},
{"24", "* {: id=\"20220810110631-x6ycsc2\"}foo\n {: id=\"20220810110631-3ppdll8\"}\n* {: id=\"20220810110631-txapkc7\"}bar\n {: id=\"20220810110631-c5cuvm5\"}\n* {: id=\"20220810110631-fdlccs9\"}\n {: id=\"20220810110631-56rznx9\"}\n{: id=\"20220810110631-jjbmho2\"}\n\nbaz\n{: id=\"20220810110631-bmiq3pg\"}", "<ul id=\"20220810110631-jjbmho2\">\n<li id=\"20220810110631-x6ycsc2\">foo</li>\n<li id=\"20220810110631-txapkc7\">bar</li>\n<li id=\"20220810110631-fdlccs9\"></li>\n</ul>\n<p id=\"20220810110631-bmiq3pg\">baz</p>\n"},
{"23", "* {: id=\"20210410235101-qckdxca\"}foo\n {: id=\"20210411001135-u2jnm4r\"}\n\n {: id=\"20210411001219-0t9swv3\"}\n{: id=\"20210410181814-3ar1jd9\"}\n\n\n{: id=\"20210410173314-j8kfyel\" type=\"doc\"}\n", "<ul id=\"20210410181814-3ar1jd9\">\n<li id=\"20210410235101-qckdxca\">\n<p id=\"20210411001135-u2jnm4r\">foo</p>\n<p id=\"20210411001219-0t9swv3\"></p>\n</li>\n</ul>\n"},
{"22", "* {: id=\"20210221200613-7vpmc8h\"}foo\n {: id=\"20210221195351-x5tgalq\" updated=\"20210221201411\"}\n{: id=\"20210221195349-czsad7f\" updated=\"20210221195351\"}\n\n\n{: id=\"20210215183533-l36k5mo\" type=\"doc\"}", "<ul id=\"20210221195349-czsad7f\" updated=\"20210221195351\">\n<li id=\"20210221200613-7vpmc8h\">foo</li>\n</ul>\n"},
Expand Down
1 change: 1 addition & 0 deletions test/m2p_test.go
Expand Up @@ -19,6 +19,7 @@ import (

var md2BlockDOMTests = []parseTest{

{"52", "<div>\n<details>\n<summary>foo</summary>\n</div>\n{: id=\"20221022222200-2b6wj74\" updated=\"20221022222200\"}\n", "<div data-node-id=\"20221022222200-2b6wj74\" data-node-index=\"1\" data-type=\"NodeHTMLBlock\" class=\"render-node\" updated=\"20221022222200\" data-subtype=\"block\"><div class=\"protyle-icons\"><span class=\"protyle-icon protyle-icon--first protyle-action__edit\"><svg><use xlink:href=\"#iconEdit\"></use></svg></span><span class=\"protyle-icon protyle-action__menu protyle-icon--last\"><svg><use xlink:href=\"#iconMore\"></use></svg></span></div><div><protyle-html data-content=\"&lt;div&gt;\n&lt;details&gt;\n&lt;summary&gt;foo&lt;/summary&gt;\n&lt;/div&gt;\"></protyle-html><span style=\"position: absolute\">\u200b</span></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"51", "~~~foo~~~", "<div data-node-id=\"20060102150405-1a2b3c4\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20060102150405\"><div contenteditable=\"true\" spellcheck=\"false\"><span data-type=\"sub s\">foo</span></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"50", "#foo'bar#", "<div data-node-id=\"20060102150405-1a2b3c4\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20060102150405\"><div contenteditable=\"true\" spellcheck=\"false\">\u200b<span data-type=\"tag\">\u200bfoo'bar</span>\u200b</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"49", "*foo$bar$baz*", "<div data-node-id=\"20060102150405-1a2b3c4\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20060102150405\"><div contenteditable=\"true\" spellcheck=\"false\"><span data-type=\"em\">foo</span> <span data-type=\"em inline-math\" data-subtype=\"math\" data-content=\"bar\" contenteditable=\"false\" class=\"render-node\"></span> <span data-type=\"em\">baz</span></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
Expand Down

0 comments on commit 92ba7f9

Please sign in to comment.