Skip to content

Commit

Permalink
🎨 Protyle Improve AI-generated content parsing siyuan-note/siyuan#10217
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jan 18, 2024
1 parent 2de70d7 commit c72dc89
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 4 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.

2 changes: 2 additions & 0 deletions parse/code_span.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ func (t *Tree) parseCodeSpan(block *ast.Node, ctx *InlineContext) (ret *ast.Node
} else if ast.NodeBackslashContent == n.Type {
content.WriteString("\\")
content.Write(n.Tokens)
} else if ast.NodeHTMLEntity == n.Type {
content.Write(n.Tokens)
}
return ast.WalkContinue
})
Expand Down
4 changes: 4 additions & 0 deletions protyle.go
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,10 @@ func (lute *Lute) genASTContenteditable(n *html.Node, tree *parse.Tree) {
return
}

if html.ElementNode == n.Type {
node.Tokens = util.StrToBytes("<" + content + ">")
}

if ast.NodeLink == tree.Context.Tip.Type {
node.Type = ast.NodeLinkText
} else if ast.NodeHeading == tree.Context.Tip.Type {
Expand Down
2 changes: 1 addition & 1 deletion test/p2p_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var blockDOM2InlineBlockDOM = []parseTest{

{"8", "<div data-node-id=\"20231108094403-j76zf5u\" data-node-index=\"1\" data-type=\"NodeTable\" class=\"table\" updated=\"20231108094403\"><div contenteditable=\"false\"><table contenteditable=\"true\" spellcheck=\"false\"><colgroup><col /><col /></colgroup><thead><tr><th align=\"right\">1</th><th align=\"right\">2</th></tr></thead><tbody><tr><td align=\"right\">3</td><td align=\"right\">4</td></tr></tbody></table><div class=\"protyle-action__table\"><div class=\"table__resize\"></div><div class=\"table__select\"></div></div></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "1 2 3 4"},
{"7", "<div data-node-id=\"20220525090743-ueavg67\" data-node-index=\"1\" data-type=\"NodeHTMLBlock\" class=\"render-node\" updated=\"20220525090743\" 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;testnode&gt;\n &lt;name Value=&quot;1&quot; /&gt;\n &lt;value Value=&quot;1&quot; /&gt;\n &lt;description Value=&quot;1&quot; /&gt;\n &lt;note Value=&quot;0&quot; /&gt;\n &lt;/testnode&gt;\"></protyle-html><span style=\"position: absolute\">​</span></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "&lt;testnode&gt;\n &lt;name Value=&quot;1&quot; /&gt;\n &lt;value Value=&quot;1&quot; /&gt;\n &lt;description Value=&quot;1&quot; /&gt;\n &lt;note Value=&quot;0&quot; /&gt;\n &lt;/testnode&gt;"},
{"6", "<testnode>\n <name Value=\"1\" />\n <value Value=\"1\" />\n <description Value=\"1\" />\n <note Value=\"0\" />\n </testnode>", "testnode description\n note"},
{"6", "<testnode>\n <name Value=\"1\" />\n <value Value=\"1\" />\n <description Value=\"1\" />\n <note Value=\"0\" />\n </testnode>", "&lt;testnode&gt; &lt;description&gt;\n &lt;note&gt;"},
{"5", "<div data-subtype=\"t\" data-node-id=\"20220325100509-t05nmj6\" data-node-index=\"2\" data-type=\"NodeList\" class=\"list\" updated=\"20220325100509\"><div data-marker=\"*\" data-subtype=\"t\" data-node-id=\"20220325100509-skwrk4f\" data-type=\"NodeListItem\" class=\"li\"><div class=\"protyle-action protyle-action--task\"><svg><use xlink:href=\"#iconUncheck\"></use></svg></div><div data-node-id=\"20220325100509-r89zejn\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220325100509\"><div contenteditable=\"true\" spellcheck=\"false\">foo</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div data-marker=\"*\" data-subtype=\"t\" data-node-id=\"20220325100509-hhbowb2\" data-type=\"NodeListItem\" class=\"li\" updated=\"20220325100509\"><div class=\"protyle-action protyle-action--task\"><svg><use xlink:href=\"#iconUncheck\"></use></svg></div><div data-node-id=\"20220325100509-2vhyu9m\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220325100509\"><div contenteditable=\"true\" spellcheck=\"false\">bar</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>", "foobar"},
{"4", "<div data-node-id=\"20220303220959-l05fsv1\" data-node-index=\"1\" data-type=\"NodeCodeBlock\" class=\"code-block\" updated=\"20220303220959\" data-eof=\"true\"><div class=\"protyle-action protyle-icons\"><span class=\"protyle-action__language\" contenteditable=\"false\"></span><span class=\"protyle-action__copy b3-tooltips b3-tooltips__nw\" aria-label=\"复制\"><svg><use xlink:href=\"#iconCopy\"></use></svg></span></div><div contenteditable=\"true\" spellcheck=\"false\" class=\"hljs protyle-linenumber\" data-render=\"true\" style=\"white-space: pre-wrap; word-break: break-all; font-variant-ligatures: none;\">var a = 1\n</div><span contenteditable=\"false\" class=\"protyle-linenumber__rows\"><span style=\"height:22px;\"></span></span><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", ""},
{"3", "a<br>b<br>c", "a<br />b<br />c"},
Expand Down
3 changes: 3 additions & 0 deletions test/spin_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import (

var spinBlockDOMTests = []*parseTest{

{"216", "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\">foo <span data-type=\"code\">\u200b&lt;bar&gt;</span>\u200b baz</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"215", "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\">foo <span data-type=\"code\">\u200b&lt;bar&gt;</span>\u200b baz</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"214", "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\">foo&lt;bar&gt;baz</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"213", "<div data-node-id=\"20240107150436-5y8mdyj\" data-node-index=\"4\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20240107153500\" style=\"background-color: var(--b3-card-error-background); color: var(--b3-card-error-color);\"><div contenteditable=\"true\" spellcheck=\"false\">foo\n\nb<wbr></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20240107150436-5y8mdyj\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" style=\"background-color: var(--b3-card-error-background); color: var(--b3-card-error-color);\" updated=\"20240107153500\"><div contenteditable=\"true\" spellcheck=\"false\">foo</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div data-node-id=\"20060102150405-1a2b3c4\" data-node-index=\"2\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20060102150405\"><div contenteditable=\"true\" spellcheck=\"false\">b<wbr></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"212", "<div data-node-id=\"20231202195719-0j1mozn\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20231202213354\"><div contenteditable=\"true\" spellcheck=\"false\">`<span data-type=\"strong\">foo`<wbr></span></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20231202195719-0j1mozn\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20231202213354\"><div contenteditable=\"true\" spellcheck=\"false\">\u200b<span data-type=\"code\">\u200bfoo</span>\u200b<wbr></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"211", "<div data-node-id=\"20231202195719-0j1mozn\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20231202205111\"><div contenteditable=\"true\" spellcheck=\"false\">`<span data-type=\"code\">​&lt;div&gt;foo&lt;/div&gt;</span>​`<wbr></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20231202195719-0j1mozn\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20231202205111\"><div contenteditable=\"true\" spellcheck=\"false\">\u200b<span data-type=\"code\">\u200b&lt;div&gt;foo&lt;/div&gt;</span>\u200b<wbr></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
Expand Down

0 comments on commit c72dc89

Please sign in to comment.