mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 Markdown syntax switch no longer affects clip/paste HTML parsing https://github.com/siyuan-note/siyuan/issues/11604
This commit is contained in:
parent
505cf51efe
commit
7c6ff6b55f
6 changed files with 14 additions and 12 deletions
8
app/stage/protyle/js/lute/lute.min.js
vendored
8
app/stage/protyle/js/lute/lute.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -123,6 +123,7 @@ func extensionCopy(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
luteEngine := util.NewLute()
|
luteEngine := util.NewLute()
|
||||||
|
luteEngine.SetHTMLTag2TextMark(true)
|
||||||
var md string
|
var md string
|
||||||
var withMath bool
|
var withMath bool
|
||||||
if nil != form.Value["href"] {
|
if nil != form.Value["href"] {
|
||||||
|
|
@ -175,7 +176,7 @@ func extensionCopy(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if "" == md {
|
if "" == md {
|
||||||
md, withMath, _ = model.HTML2Markdown(dom)
|
md, withMath, _ = model.HTML2Markdown(dom, luteEngine)
|
||||||
}
|
}
|
||||||
|
|
||||||
md = strings.TrimSpace(md)
|
md = strings.TrimSpace(md)
|
||||||
|
|
|
||||||
|
|
@ -57,13 +57,14 @@ func html2BlockDOM(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
dom := arg["dom"].(string)
|
dom := arg["dom"].(string)
|
||||||
markdown, withMath, err := model.HTML2Markdown(dom)
|
luteEngine := util.NewLute()
|
||||||
|
luteEngine.SetHTMLTag2TextMark(true)
|
||||||
|
markdown, withMath, err := model.HTML2Markdown(dom, luteEngine)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ret.Data = "Failed to convert"
|
ret.Data = "Failed to convert"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
luteEngine := util.NewLute()
|
|
||||||
if withMath {
|
if withMath {
|
||||||
luteEngine.SetInlineMath(true)
|
luteEngine.SetInlineMath(true)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ require (
|
||||||
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
|
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
|
||||||
github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7
|
github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7
|
||||||
github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02
|
github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02
|
||||||
github.com/88250/lute v1.7.7-0.20241028035735-91bbe8c1a561
|
github.com/88250/lute v1.7.7-0.20241029093436-435765ab45e6
|
||||||
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
|
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
|
||||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
|
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
|
||||||
github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4
|
github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950 h1:Pa5hMiBceT
|
||||||
github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||||
github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02 h1:3e5+yobj655pTeKOYMbJrnc1mE51ZkbXIxquTYZuYCY=
|
github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02 h1:3e5+yobj655pTeKOYMbJrnc1mE51ZkbXIxquTYZuYCY=
|
||||||
github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8=
|
github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8=
|
||||||
github.com/88250/lute v1.7.7-0.20241028035735-91bbe8c1a561 h1:m0Akk/6lc7329W1QUWpy5Fph9W1poRYs1JSvCCxX/fQ=
|
github.com/88250/lute v1.7.7-0.20241029093436-435765ab45e6 h1:knKOryX3TDBe2Dro6kLTUdYNo81+8ixCfDocqVRwVhY=
|
||||||
github.com/88250/lute v1.7.7-0.20241028035735-91bbe8c1a561/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
|
github.com/88250/lute v1.7.7-0.20241029093436-435765ab45e6/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
|
||||||
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
|
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
|
||||||
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
|
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
|
||||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=
|
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/88250/lute"
|
||||||
"image"
|
"image"
|
||||||
"image/jpeg"
|
"image/jpeg"
|
||||||
"image/png"
|
"image/png"
|
||||||
|
|
@ -54,9 +55,8 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HTML2Markdown(htmlStr string) (markdown string, withMath bool, err error) {
|
func HTML2Markdown(htmlStr string, luteEngine *lute.Lute) (markdown string, withMath bool, err error) {
|
||||||
assetDirPath := filepath.Join(util.DataDir, "assets")
|
assetDirPath := filepath.Join(util.DataDir, "assets")
|
||||||
luteEngine := util.NewLute()
|
|
||||||
tree := luteEngine.HTML2Tree(htmlStr)
|
tree := luteEngine.HTML2Tree(htmlStr)
|
||||||
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||||
if !entering {
|
if !entering {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue