This commit is contained in:
Daniel 2024-11-15 13:13:43 +08:00
parent ab147598e1
commit e408546be5
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 40 additions and 22 deletions

View file

@ -123,7 +123,12 @@ func extensionCopy(c *gin.Context) {
}
luteEngine := util.NewLute()
luteEngine.SetHTMLTag2TextMark(true)
luteEngine.SetSup(true)
luteEngine.SetSub(true)
luteEngine.SetMark(true)
luteEngine.SetGFMStrikethrough(true)
luteEngine.SetInlineAsterisk(true)
luteEngine.SetInlineUnderscore(true)
var md string
var withMath bool
if nil != form.Value["href"] {
@ -175,16 +180,19 @@ func extensionCopy(c *gin.Context) {
}
}
var tree *parse.Tree
if "" == md {
md, withMath, _ = model.HTML2Markdown(dom, luteEngine)
tree, withMath = model.HTML2Tree(dom, luteEngine)
if nil == tree {
md, withMath, _ = model.HTML2Markdown(dom, luteEngine)
if withMath {
luteEngine.SetInlineMath(true)
}
tree = parse.Parse("", []byte(md), luteEngine.ParseOptions)
}
}
md = strings.TrimSpace(md)
if withMath {
luteEngine.SetInlineMath(true)
}
var unlinks []*ast.Node
tree := parse.Parse("", []byte(md), luteEngine.ParseOptions)
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering {
return ast.WalkContinue