Skip to content

Commit

Permalink
🎨 Improve HTML math clipping siyuan-note/siyuan#12677
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Oct 13, 2024
1 parent ffbe851 commit c58c752
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
12 changes: 10 additions & 2 deletions h2m.go
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,9 @@ func (lute *Lute) genASTByDOM(n *html.Node, tree *parse.Tree) {
return
case atom.Script:
if tex := util.DomText(n.FirstChild); "" != tex {
if tree.Context.Tip.IsContainerBlock() {
if tree.Context.Tip.IsContainerBlock() ||
(nil != n.Parent && strings.Contains(util.DomAttrValue(n.Parent, "class"), "math display") && n.Parent.LastChild == n) ||
strings.Contains(util.DomAttrValue(n, "type"), "mode=display") {
appendMathBlock(tree, tex)
} else {
appendInlineMath(tree, tex)
Expand Down Expand Up @@ -1271,7 +1273,13 @@ func appendMathBlock(tree *parse.Tree, tex string) {
mathBlock.AppendChild(&ast.Node{Type: ast.NodeMathBlockOpenMarker, Tokens: []byte("$$")})
mathBlock.AppendChild(&ast.Node{Type: ast.NodeMathBlockContent, Tokens: util.StrToBytes(tex)})
mathBlock.AppendChild(&ast.Node{Type: ast.NodeMathBlockCloseMarker, Tokens: []byte("$$")})
tree.Context.Tip.AppendChild(mathBlock)

if ast.NodeParagraph == tree.Context.Tip.Type {
tree.Context.Tip.InsertAfter(mathBlock)
tree.Context.Tip.Unlink()
} else {
tree.Context.Tip.AppendChild(mathBlock)
}
tree.Context.Tip = mathBlock
defer tree.Context.ParentTip()
}
Expand Down
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.

Loading

0 comments on commit c58c752

Please sign in to comment.