mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 改进 Edge 浏览器 Web 选择 复制 Fix https://github.com/siyuan-note/siyuan/issues/7021
This commit is contained in:
parent
751c1df6b6
commit
5cf817c3a2
6 changed files with 41 additions and 11 deletions
|
|
@ -195,7 +195,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
|||
textHTML = textHTML.replace("<!--StartFragment-->", "").replace("<!--EndFragment-->", "").trim();
|
||||
if (files && files.length === 1 && (
|
||||
textHTML.startsWith("<img") || // 浏览器上复制单个图片
|
||||
(textHTML.startsWith("<table") && textHTML.split("<table").length === 2 && textHTML.indexOf("<img") > -1) // excel 中的复制带有图片的表格
|
||||
(textHTML.startsWith("<table") && textHTML.indexOf("<img") > -1) // Excel 或者浏览器中复制带有图片的表格
|
||||
)) {
|
||||
isHTML = false;
|
||||
} else {
|
||||
|
|
|
|||
2
app/stage/protyle/js/lute/lute.min.js
vendored
2
app/stage/protyle/js/lute/lute.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -55,13 +55,13 @@ func html2BlockDOM(c *gin.Context) {
|
|||
}
|
||||
|
||||
dom := arg["dom"].(string)
|
||||
luteEngine := model.NewLute()
|
||||
markdown, err := luteEngine.HTML2Markdown(dom)
|
||||
markdown, err := model.HTML2Markdown(dom)
|
||||
if nil != err {
|
||||
ret.Data = "Failed to convert"
|
||||
return
|
||||
}
|
||||
|
||||
luteEngine := model.NewLute()
|
||||
var unlinks []*ast.Node
|
||||
tree := parse.Parse("", []byte(markdown), luteEngine.ParseOptions)
|
||||
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ require (
|
|||
github.com/88250/clipboard v0.1.5
|
||||
github.com/88250/css v0.1.2
|
||||
github.com/88250/gulu v1.2.3-0.20221117052724-cd06804db798
|
||||
github.com/88250/lute v1.7.5-0.20230105013116-b3175d9d81f8
|
||||
github.com/88250/lute v1.7.5-0.20230109135528-9a4b82cd4447
|
||||
github.com/88250/pdfcpu v0.3.13
|
||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
|
||||
github.com/ConradIrwin/font v0.0.0-20210318200717-ce8d41cc0732
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ github.com/88250/gulu v1.2.3-0.20221117052724-cd06804db798 h1:sR/s/Y9wyl79ZRCUER
|
|||
github.com/88250/gulu v1.2.3-0.20221117052724-cd06804db798/go.mod h1:I1qBzsksFL2ciGSuqDE7R3XW4BUMrfDgOvSXEk7FsAI=
|
||||
github.com/88250/lute v1.7.5-0.20230105013116-b3175d9d81f8 h1:C04h1Xiye42GdB+CH7TnxQmEF/zeAZC5G3/aYVco98E=
|
||||
github.com/88250/lute v1.7.5-0.20230105013116-b3175d9d81f8/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
|
||||
github.com/88250/lute v1.7.5-0.20230109135528-9a4b82cd4447 h1:AvdRSsM1BC7mdPyigd6IkJbxl+VooZ3N0mxWTTpIR3I=
|
||||
github.com/88250/lute v1.7.5-0.20230109135528-9a4b82cd4447/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
|
||||
github.com/88250/pdfcpu v0.3.13 h1:touMWMZkCGalMIbEg9bxYp7rETM+zwb9hXjwhqi4I7Q=
|
||||
github.com/88250/pdfcpu v0.3.13/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
|
||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=
|
||||
|
|
|
|||
|
|
@ -51,6 +51,34 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func HTML2Markdown(htmlStr string) (markdown string, err error) {
|
||||
assetDirPath := filepath.Join(util.DataDir, "assets")
|
||||
luteEngine := NewLute()
|
||||
luteEngine.SetProtyleWYSIWYG(false)
|
||||
tree := luteEngine.HTML2Tree(htmlStr)
|
||||
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering || ast.NodeLinkDest != n.Type {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
dest := n.TokensStr()
|
||||
if strings.HasPrefix(dest, "data:image") && strings.Contains(dest, ";base64,") {
|
||||
processBase64Img(n, dest, assetDirPath, err)
|
||||
return ast.WalkContinue
|
||||
}
|
||||
return ast.WalkContinue
|
||||
})
|
||||
|
||||
var formatted []byte
|
||||
renderer := render.NewFormatRenderer(tree, luteEngine.RenderOptions)
|
||||
for nodeType, rendererFunc := range luteEngine.HTML2MdRendererFuncs {
|
||||
renderer.ExtRendererFuncs[nodeType] = rendererFunc
|
||||
}
|
||||
formatted = renderer.Render()
|
||||
markdown = gulu.Str.FromBytes(formatted)
|
||||
return
|
||||
}
|
||||
|
||||
func ImportSY(zipPath, boxID, toPath string) (err error) {
|
||||
util.PushEndlessProgress(Conf.Language(73))
|
||||
defer util.ClearPushProgress(100)
|
||||
|
|
@ -402,9 +430,6 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
}
|
||||
boxLocalPath = filepath.Join(util.DataDir, boxID)
|
||||
|
||||
base64TmpDir := filepath.Join(util.TempDir, "base64")
|
||||
os.MkdirAll(base64TmpDir, 0755)
|
||||
|
||||
if gulu.File.IsDir(localPath) {
|
||||
// 收集所有资源文件
|
||||
assets := map[string]string{}
|
||||
|
|
@ -508,7 +533,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
|
||||
dest := n.TokensStr()
|
||||
if strings.HasPrefix(dest, "data:image") && strings.Contains(dest, ";base64,") {
|
||||
processBase64Img(n, dest, base64TmpDir, assetDirPath, err)
|
||||
processBase64Img(n, dest, assetDirPath, err)
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
|
|
@ -608,7 +633,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
|
||||
dest := n.TokensStr()
|
||||
if strings.HasPrefix(dest, "data:image") && strings.Contains(dest, ";base64,") {
|
||||
processBase64Img(n, dest, base64TmpDir, assetDirPath, err)
|
||||
processBase64Img(n, dest, assetDirPath, err)
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
|
|
@ -660,7 +685,10 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func processBase64Img(n *ast.Node, dest string, base64TmpDir string, assetDirPath string, err error) {
|
||||
func processBase64Img(n *ast.Node, dest string, assetDirPath string, err error) {
|
||||
base64TmpDir := filepath.Join(util.TempDir, "base64")
|
||||
os.MkdirAll(base64TmpDir, 0755)
|
||||
|
||||
sep := strings.Index(dest, ";base64,")
|
||||
var decodeErr error
|
||||
unbased, decodeErr := base64.StdEncoding.DecodeString(dest[sep+8:])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue