🎨 Support convert Base64 image when clipping HTML https://github.com/siyuan-note/siyuan/issues/11210

This commit is contained in:
Daniel 2024-05-01 16:38:49 +08:00
parent 1f6f7c44d7
commit 04ba3ed011
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 6 additions and 2 deletions

View file

@ -122,7 +122,7 @@ func extensionCopy(c *gin.Context) {
}
luteEngine := util.NewStdLute()
md := luteEngine.HTML2Md(dom)
md, _ := model.HTML2Markdown(dom)
md = strings.TrimSpace(md)
var unlinks []*ast.Node

View file

@ -33,6 +33,7 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"runtime/debug"
"sort"
"strconv"
@ -927,8 +928,11 @@ func processBase64Img(n *ast.Node, dest string, assetDirPath string, err error)
os.MkdirAll(base64TmpDir, 0755)
sep := strings.Index(dest, ";base64,")
str := strings.TrimSpace(dest[sep+8:])
re := regexp.MustCompile(`(?i)%0A`)
str = re.ReplaceAllString(str, "\n")
var decodeErr error
unbased, decodeErr := base64.StdEncoding.DecodeString(dest[sep+8:])
unbased, decodeErr := base64.StdEncoding.DecodeString(str)
if nil != decodeErr {
logging.LogErrorf("decode base64 image failed: %s", decodeErr)
return