Skip to content

Commit 77ff1f8

Browse files
committed
🎨 Improve Optimize typography for inline math siyuan-note/siyuan#14344
1 parent 1b5c5c1 commit 77ff1f8

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

ast/node.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -689,10 +689,17 @@ func (n *Node) NextNodeText() string {
689689
}
690690

691691
func (n *Node) PreviousNodeText() string {
692-
if nil == n.Previous {
692+
prev := n.Previous
693+
if nil == prev {
693694
return ""
694695
}
695-
return n.Previous.Text()
696+
if NodeKramdownSpanIAL == prev.Type {
697+
prev = prev.Previous
698+
}
699+
if nil == prev {
700+
return ""
701+
}
702+
return prev.Text()
696703
}
697704

698705
// Unlink 用于将节点从树上移除,后一个兄弟节点会接替该节点。

javascript/lute.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

javascript/lute.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

render/format_renderer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ func (r *FormatRenderer) renderKramdownSpanIAL(node *ast.Node, entering bool) as
582582
if entering {
583583
r.Write(node.Tokens)
584584
} else {
585-
if previous := node.Previous; nil != previous && parse.ContainTextMark(previous, "code", "inline-math", "kbd") {
585+
if previous := node.Previous; nil != previous && parse.ContainTextMark(previous, "code", "inline-math", "kbd") && r.Options.AutoSpace {
586586
if text := node.NextNodeText(); "" != text {
587587
firstc, _ := utf8.DecodeRuneInString(text)
588588
if editor.Zwsp == string(firstc) {

test/spin_block_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
var spinBlockDOMTests = []*parseTest{
2121

22+
{"245", "<span data-type=\"text\" style=\"color: var(--b3-font-color6);\">你好</span><span data-type=\"inline-math strong text\" data-subtype=\"math\" data-content=\"foo\" contenteditable=\"false\" class=\"render-node\" style=\"color: var(--b3-font-color6);\" data-render=\"true\"><span class=\"katex\"><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.8889em;vertical-align:-0.1944em;\"></span><span class=\"mord mathnormal\" style=\"margin-right:0.10764em;\">f</span><span class=\"mord mathnormal\">oo</span></span></span></span></span><span data-type=\"text\" style=\"color: var(--b3-font-color6);\">世界</span>", "<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=\"text\" style=\"color: var(--b3-font-color6);\">你好</span> <span data-type=\"inline-math strong text\" data-subtype=\"math\" data-content=\"foo\" contenteditable=\"false\" class=\"render-node\" style=\"color: var(--b3-font-color6);\"></span><span data-type=\"text\" style=\"color: var(--b3-font-color6);\">世界</span></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
2223
{"244", "<div data-node-id=\"20250217115226-bvwjazt\" data-node-index=\"1\" data-type=\"NodeCodeBlock\" class=\"code-block\" updated=\"20250217115230\"><div class=\"protyle-action\"><span class=\"protyle-action--first protyle-action__language\" contenteditable=\"false\">plaintext</span><span class=\"fn__flex-1\"></span><span class=\"b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--first protyle-action__copy\" aria-label=\"复制\"><svg><use xlink:href=\"#iconCopy\"></use></svg></span><span class=\"b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--last protyle-action__menu\" aria-label=\"更多\"><svg><use xlink:href=\"#iconMore\"></use></svg></span></div><div class=\"hljs\" style=\"display: block;\"><div class=\"fn__none\"></div><div contenteditable=\"true\" style=\"flex: 1 1 0%; white-space: pre; word-break: initial; font-variant-ligatures: none;\" spellcheck=\"false\">on\ttest01\t\t R \t\non\ttest02\t\t R \t\n<wbr>\n</div></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20250217115226-bvwjazt\" data-node-index=\"1\" data-type=\"NodeCodeBlock\" class=\"code-block\" updated=\"20250217115230\"><div class=\"protyle-action\"><span class=\"protyle-action--first protyle-action__language\" contenteditable=\"false\">plaintext</span><span class=\"fn__flex-1\"></span><span class=\"b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--first protyle-action__copy\"><svg><use xlink:href=\"#iconCopy\"></use></svg></span><span class=\"b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--last protyle-action__menu\"><svg><use xlink:href=\"#iconMore\"></use></svg></span></div><div class=\"hljs\"><div></div><div contenteditable=\"true\" style=\"flex: 1\" spellcheck=\"false\">on\ttest01\t\t R \t\non\ttest02\t\t R \t\n<wbr>\n</div></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
2324
{"243", "<div data-node-id=\"20250110101312-66lfej5\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20250110104805\"><div contenteditable=\"true\" spellcheck=\"false\">fo`<wbr>o<span data-type=\"text\" style=\"background-color: var(--b3-font-background3);\">ba`r</span>baz</div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20250110101312-66lfej5\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20250110104805\"><div contenteditable=\"true\" spellcheck=\"false\">fo <span data-type=\"code\">\u200b<wbr>oba</span>\u200b rbaz</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
2425
{"242", "<div data-node-id=\"20250110101312-66lfej5\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20250110101556\"><div contenteditable=\"true\" spellcheck=\"false\">f`<wbr>oo<span data-type=\"strong\">ba`r</span>baz</div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20250110101312-66lfej5\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20250110101556\"><div contenteditable=\"true\" spellcheck=\"false\">f <span data-type=\"code\">\u200b<wbr>ooba</span>\u200b rbaz</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},

0 commit comments

Comments
 (0)