mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-21 14:34:06 +01:00
🎨 The browser extension supports CSDN formula https://github.com/siyuan-note/siyuan/issues/5624
This commit is contained in:
parent
dfc8d39a68
commit
d3754bd630
5 changed files with 34 additions and 9 deletions
|
|
@ -1138,7 +1138,7 @@ func CreateDocByMd(boxID, p, title, md string, sorts []string) (tree *parse.Tree
|
|||
return
|
||||
}
|
||||
|
||||
func CreateWithMarkdown(boxID, hPath, md, parentID, id string) (retID string, err error) {
|
||||
func CreateWithMarkdown(boxID, hPath, md, parentID, id string, withMath bool) (retID string, err error) {
|
||||
createDocLock.Lock()
|
||||
defer createDocLock.Unlock()
|
||||
|
||||
|
|
@ -1150,6 +1150,9 @@ func CreateWithMarkdown(boxID, hPath, md, parentID, id string) (retID string, er
|
|||
|
||||
WaitForWritingFiles()
|
||||
luteEngine := util.NewLute()
|
||||
if withMath {
|
||||
luteEngine.SetInlineMath(true)
|
||||
}
|
||||
dom := luteEngine.Md2BlockDOM(md, false)
|
||||
retID, err = createDocsByHPath(box.ID, hPath, dom, parentID, id)
|
||||
WaitForWritingFiles()
|
||||
|
|
|
|||
|
|
@ -55,12 +55,21 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func HTML2Markdown(htmlStr string) (markdown string, err error) {
|
||||
func HTML2Markdown(htmlStr string) (markdown string, withMath bool, err error) {
|
||||
assetDirPath := filepath.Join(util.DataDir, "assets")
|
||||
luteEngine := util.NewLute()
|
||||
tree := luteEngine.HTML2Tree(htmlStr)
|
||||
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering || ast.NodeLinkDest != n.Type {
|
||||
if !entering {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
if ast.NodeInlineMath == n.Type {
|
||||
withMath = true
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
if ast.NodeLinkDest != n.Type {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue