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 4, 2024
1 parent 3fb25e6 commit ad5b8f2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
19 changes: 19 additions & 0 deletions h2m.go
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,25 @@ func (lute *Lute) genASTByDOM(n *html.Node, tree *parse.Tree) {

// The browser extension supports Zhihu formula https://github.com/siyuan-note/siyuan/issues/5599
if tex := strings.TrimSpace(util.DomAttrValue(n, "data-tex")); "" != tex {
if nil != n.Parent && strings.Contains(util.DomAttrValue(n.Parent, "class"), "math-inline") {
appendInlineMath(tree, tex)
return
}

parentInline := nil != n.Parent && atom.Span == n.Parent.DataAtom
if parentInline && atom.Span == n.DataAtom &&
nil == n.Parent.PrevSibling && (nil == n.Parent.NextSibling || (html.TextNode == n.Parent.NextSibling.Type && "" == strings.TrimSpace(util.DomText(n.Parent.NextSibling)))) {
// 作为独立的公式块转换
appendMathBlock(tree, tex)
return
}

if !parentInline && nil == n.PrevSibling && (nil == n.NextSibling || (html.TextNode == n.NextSibling.Type && "" == strings.TrimSpace(util.DomText(n.NextSibling)))) {
// 作为独立的公式块转换
appendMathBlock(tree, tex)
return
}

if strings.HasSuffix(strings.TrimSpace(tex), "\\\\") || strings.Contains(tex, "\n") {
appendMathBlock(tree, tex)
} else {
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 ad5b8f2

Please sign in to comment.