Skip to content

Commit

Permalink
🎨 Improve blocks conversion siyuan-note/siyuan#11851
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jul 2, 2024
1 parent e06da47 commit ee02f91
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 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: 3 additions & 0 deletions protyle.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,9 @@ func (lute *Lute) Blocks2Hs(ivHTML, level string) (ovHTML string) {
for p := node; nil != p; p = p.Next {
if ast.NodeParagraph == p.Type || ast.NodeHeading == p.Type {
p.Type = ast.NodeHeading
if nil != p.FirstChild {
p.FirstChild.Tokens = bytes.ReplaceAll(p.FirstChild.Tokens, []byte("\n"), nil)
}
p.HeadingLevel, _ = strconv.Atoi(level)
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/block_type_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func TestBlocks2Ps(t *testing.T) {
}

var blocks2hsTests = []*parseTest{

{"2", "<div data-node-id=\"20240702163651-4ww2c7k\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20240702163654\"><div contenteditable=\"true\" spellcheck=\"false\">foo\nbar</div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-subtype=\"h1\" data-node-id=\"20240702163651-4ww2c7k\" data-node-index=\"1\" data-type=\"NodeHeading\" class=\"h1\" updated=\"20240702163654\"><div contenteditable=\"true\" spellcheck=\"false\">foobar</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"1", "<div data-subtype=\"h2\" data-node-id=\"20210610154900-5r20m2j\" data-node-index=\"1\" data-type=\"NodeHeading\" class=\"h2\" updated=\"20210610154902\"><div contenteditable=\"true\" spellcheck=\"false\">foo</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div data-subtype=\"h2\" data-node-id=\"20210610154909-wemyt8x\" data-node-index=\"2\" data-type=\"NodeHeading\" class=\"h2\" updated=\"20210610154910\"><div contenteditable=\"true\" spellcheck=\"false\">bar</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>", "<div data-subtype=\"h1\" data-node-id=\"20210610154900-5r20m2j\" data-node-index=\"1\" data-type=\"NodeHeading\" class=\"h1\" updated=\"20210610154902\"><div contenteditable=\"true\" spellcheck=\"false\">foo</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div data-subtype=\"h1\" data-node-id=\"20210610154909-wemyt8x\" data-node-index=\"2\" data-type=\"NodeHeading\" class=\"h1\" updated=\"20210610154910\"><div contenteditable=\"true\" spellcheck=\"false\">bar</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"0", "<div data-node-id=\"20210518185646-hjjhl5p\" data-node-index=\"0\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20210518191256\"><div contenteditable=\"true\" spellcheck=\"false\">foo</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div data-node-id=\"20210518191256-m1ij6pn\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" fold=\"0\" updated=\"20210518191257\"><div contenteditable=\"true\" spellcheck=\"false\">bar</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div data-node-id=\"20210518185646-pcdktyp\" data-node-index=\"2\" data-type=\"NodeParagraph\" class=\"p\"><div contenteditable=\"true\" spellcheck=\"false\"></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>", "<div data-subtype=\"h1\" data-node-id=\"20210518185646-hjjhl5p\" data-node-index=\"1\" data-type=\"NodeHeading\" class=\"h1\" updated=\"20210518191256\"><div contenteditable=\"true\" spellcheck=\"false\">foo</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div data-subtype=\"h1\" data-node-id=\"20210518191256-m1ij6pn\" data-node-index=\"2\" data-type=\"NodeHeading\" class=\"h1\" fold=\"0\" updated=\"20210518191257\"><div contenteditable=\"true\" spellcheck=\"false\">bar</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div><div data-subtype=\"h1\" data-node-id=\"20210518185646-pcdktyp\" data-node-index=\"3\" data-type=\"NodeHeading\" class=\"h1\"><div contenteditable=\"true\" spellcheck=\"false\"></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
}
Expand Down

0 comments on commit ee02f91

Please sign in to comment.