Skip to content

Commit

Permalink
🎨 Support converting blockquote blocks to paragraphs siyuan-note/siyu…
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Dec 20, 2023
1 parent 775fdaf commit 9cf092e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 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.

21 changes: 8 additions & 13 deletions protyle.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,19 +490,14 @@ func (lute *Lute) Blocks2Ps(ivHTML string) (ovHTML string) {
case ast.NodeHeading:
n.Type = ast.NodeParagraph
case ast.NodeBlockquote:
// 多选块类型转换 https://github.com/siyuan-note/siyuan/issues/4706
//var children []*ast.Node
//for c := n.LastChild; nil != c; c = c.Previous {
// if ast.NodeBlockquoteMarker == c.Type {
// unlinks = append(unlinks, c)
// continue
// }
// children = append(children, c)
//}
//for _, c := range children {
// n.InsertBefore(c)
//}
//unlinks = append(unlinks, n)
for c := n.FirstChild; nil != c; c = c.Next {
if ast.NodeBlockquoteMarker == c.Type {
unlinks = append(unlinks, c)
continue
}
appends = append(appends, c)
}
unlinks = append(unlinks, n)
case ast.NodeList:
for li := n.FirstChild; nil != li; li = li.Next {
for c := li.FirstChild; nil != c; c = c.Next {
Expand Down
4 changes: 1 addition & 3 deletions test/block_type_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ func TestCancelSuperBlock(t *testing.T) {
var blocks2psTests = []*parseTest{
{"2", "<div data-subtype=\"u\" data-node-id=\"20231219120217-oa6yl6b\" data-node-index=\"1\" data-type=\"NodeList\" class=\"list\" updated=\"20231219120506\"><div data-marker=\"*\" data-subtype=\"u\" data-node-id=\"20231219120506-qjotc6n\" data-type=\"NodeListItem\" class=\"li\" updated=\"20231219120506\"><div class=\"protyle-action\" draggable=\"true\"><svg><use xlink:href=\"#iconDot\"></use></svg></div><div data-node-id=\"20231219120506-dckai7w\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20231219120506\"><div contenteditable=\"true\" spellcheck=\"false\">foo</div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div data-node-id=\"20231219120509-fjj9w2d\" data-type=\"NodeList\" class=\"list\" data-subtype=\"u\"><div data-marker=\"*\" data-subtype=\"u\" data-node-id=\"20231219120509-fvl0qrv\" data-type=\"NodeListItem\" class=\"li\"><div class=\"protyle-action\" draggable=\"true\"><svg><use xlink:href=\"#iconDot\"></use></svg></div><div data-node-id=\"20231219120509-4odpk5z\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20231219120510\"><div contenteditable=\"true\" spellcheck=\"false\">bar</div><div contenteditable=\"false\" class=\"protyle-attr\">​</div></div><div class=\"protyle-attr\" contenteditable=\"false\"></div></div><div class=\"protyle-attr\" contenteditable=\"false\"></div></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div data-subtype=\"u\" data-node-id=\"20231219120223-7xqch02\" data-node-index=\"1\" data-type=\"NodeList\" class=\"list\" updated=\"20231219120511\"><div data-marker=\"*\" data-subtype=\"u\" data-node-id=\"20231219120511-ybzcnet\" data-type=\"NodeListItem\" class=\"li\" updated=\"20231219120511\"><div class=\"protyle-action\" draggable=\"true\"><svg><use xlink:href=\"#iconDot\"></use></svg></div><div data-node-id=\"20231219120511-581gs9e\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20231219120511\"><div contenteditable=\"true\" spellcheck=\"false\">foo1</div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div data-node-id=\"20231219120513-4fyeovb\" data-type=\"NodeList\" class=\"list\" data-subtype=\"u\"><div data-marker=\"*\" data-subtype=\"u\" data-node-id=\"20231219120513-tb4gg96\" data-type=\"NodeListItem\" class=\"li\"><div class=\"protyle-action\" draggable=\"true\"><svg><use xlink:href=\"#iconDot\"></use></svg></div><div data-node-id=\"20231219120513-r5ao3jn\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20231219120514\"><div contenteditable=\"true\" spellcheck=\"false\">bar1</div><div contenteditable=\"false\" class=\"protyle-attr\">​</div></div><div class=\"protyle-attr\" contenteditable=\"false\"></div></div><div class=\"protyle-attr\" contenteditable=\"false\"></div></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20231219120506-dckai7w\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20231219120506\"><div contenteditable=\"true\" spellcheck=\"false\">foo</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div data-subtype=\"u\" data-node-id=\"20231219120509-fjj9w2d\" data-node-index=\"2\" data-type=\"NodeList\" class=\"list\"><div data-marker=\"*\" data-subtype=\"u\" data-node-id=\"20231219120509-fvl0qrv\" data-type=\"NodeListItem\" class=\"li\"><div class=\"protyle-action\" draggable=\"true\"><svg><use xlink:href=\"#iconDot\"></use></svg></div><div data-node-id=\"20231219120509-4odpk5z\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20231219120510\"><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><div data-node-id=\"20231219120511-581gs9e\" data-node-index=\"3\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20231219120511\"><div contenteditable=\"true\" spellcheck=\"false\">foo1</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div data-subtype=\"u\" data-node-id=\"20231219120513-4fyeovb\" data-node-index=\"4\" data-type=\"NodeList\" class=\"list\"><div data-marker=\"*\" data-subtype=\"u\" data-node-id=\"20231219120513-tb4gg96\" data-type=\"NodeListItem\" class=\"li\"><div class=\"protyle-action\" draggable=\"true\"><svg><use xlink:href=\"#iconDot\"></use></svg></div><div data-node-id=\"20231219120513-r5ao3jn\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20231219120514\"><div contenteditable=\"true\" spellcheck=\"false\">bar1</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>"},
{"1", "<div data-subtype=\"u\" data-node-id=\"20231219110700-cjhm3pd\" data-node-index=\"1\" data-type=\"NodeList\" class=\"list\" updated=\"20231219113459\"><div data-marker=\"*\" data-subtype=\"u\" data-node-id=\"20231219110702-z9t33x1\" data-type=\"NodeListItem\" class=\"li\" updated=\"20231219113459\"><div class=\"protyle-action\" draggable=\"true\"><svg><use xlink:href=\"#iconDot\"></use></svg></div><div data-node-id=\"20231219113527-focntxe\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20231219113530\"><div contenteditable=\"true\" spellcheck=\"false\">foo</div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div data-subtype=\"u\" data-node-id=\"20231219114338-lyf6uer\" data-node-index=\"2\" data-type=\"NodeList\" class=\"list\" updated=\"20231219114340\"><div data-marker=\"*\" data-subtype=\"u\" data-node-id=\"20231219114340-d4yq4f9\" data-type=\"NodeListItem\" class=\"li\" updated=\"20231219114340\"><div class=\"protyle-action\" draggable=\"true\"><svg><use xlink:href=\"#iconDot\"></use></svg></div><div data-node-id=\"20231219114340-ij6r9wa\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20231219114341\"><div contenteditable=\"true\" spellcheck=\"false\">bar</div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20231219113527-focntxe\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20231219113530\"><div contenteditable=\"true\" spellcheck=\"false\">foo</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div data-node-id=\"20231219114340-ij6r9wa\" data-node-index=\"2\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20231219114341\"><div contenteditable=\"true\" spellcheck=\"false\">bar</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},

// 多选引述块后转换为段落块 https://github.com/siyuan-note/siyuan/issues/4706
//{"0", "<div data-node-id=\"20220426231411-0xk2nas\" data-node-index=\"0\" data-type=\"NodeBlockquote\" class=\"bq\" updated=\"20220426233927\"><div data-node-id=\"20220426233908-2ocolr9\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220426233927\"><div contenteditable=\"true\" spellcheck=\"false\">foo</div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div data-node-id=\"20220426231415-p90jao5\" data-node-index=\"1\" data-type=\"NodeBlockquote\" class=\"bq\" updated=\"20220426233910\"><div data-node-id=\"20220426233910-fzxzuf7\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220426233910\"><div contenteditable=\"true\" spellcheck=\"false\">bar</div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div data-node-id=\"20220426233911-bfxns1v\" data-node-index=\"2\" data-type=\"NodeBlockquote\" class=\"bq\" updated=\"20220426233913\"><div data-node-id=\"20220426233912-bvcbp40\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220426233913\"><div contenteditable=\"true\" spellcheck=\"false\">baz</div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20220426233908-2ocolr9\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220426233927\"><div contenteditable=\"true\" spellcheck=\"false\">foo</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div data-node-id=\"20220426233910-fzxzuf7\" data-node-index=\"2\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220426233910\"><div contenteditable=\"true\" spellcheck=\"false\">bar</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div data-node-id=\"20220426233912-bvcbp40\" data-node-index=\"3\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220426233913\"><div contenteditable=\"true\" spellcheck=\"false\">baz</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"0", "<div data-node-id=\"20220426231411-0xk2nas\" data-node-index=\"0\" data-type=\"NodeBlockquote\" class=\"bq\" updated=\"20220426233927\"><div data-node-id=\"20220426233908-2ocolr9\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220426233927\"><div contenteditable=\"true\" spellcheck=\"false\">foo</div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div data-node-id=\"20220426231415-p90jao5\" data-node-index=\"1\" data-type=\"NodeBlockquote\" class=\"bq\" updated=\"20220426233910\"><div data-node-id=\"20220426233910-fzxzuf7\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220426233910\"><div contenteditable=\"true\" spellcheck=\"false\">bar</div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div data-node-id=\"20220426233911-bfxns1v\" data-node-index=\"2\" data-type=\"NodeBlockquote\" class=\"bq\" updated=\"20220426233913\"><div data-node-id=\"20220426233912-bvcbp40\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220426233913\"><div contenteditable=\"true\" spellcheck=\"false\">baz</div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20220426233908-2ocolr9\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220426233927\"><div contenteditable=\"true\" spellcheck=\"false\">foo</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div data-node-id=\"20220426233910-fzxzuf7\" data-node-index=\"2\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220426233910\"><div contenteditable=\"true\" spellcheck=\"false\">bar</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div data-node-id=\"20220426233912-bvcbp40\" data-node-index=\"3\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20220426233913\"><div contenteditable=\"true\" spellcheck=\"false\">baz</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
}

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

0 comments on commit 9cf092e

Please sign in to comment.