🎨 Improve network image convert to local image https://github.com/siyuan-note/siyuan/issues/12561

This commit is contained in:
Daniel 2024-09-23 23:44:32 +08:00
parent e4e211a260
commit ef575a1560
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -1057,10 +1057,19 @@ func assetsLinkDestsInNode(node *ast.Node) (ret []string) {
func setAssetsLinkDest(node *ast.Node, oldDest, dest string) {
if ast.NodeLinkDest == node.Type {
if bytes.HasPrefix(node.Tokens, []byte("//")) {
node.Tokens = append([]byte("https:"), node.Tokens...)
}
node.Tokens = bytes.ReplaceAll(node.Tokens, []byte(oldDest), []byte(dest))
} else if node.IsTextMarkType("a") {
if strings.HasPrefix(node.TextMarkAHref, "//") {
node.TextMarkAHref = "https:" + node.TextMarkAHref
}
node.TextMarkAHref = strings.ReplaceAll(node.TextMarkAHref, oldDest, dest)
} else if ast.NodeAudio == node.Type || ast.NodeVideo == node.Type {
if strings.HasPrefix(node.TextMarkAHref, "//") {
node.TextMarkAHref = "https:" + node.TextMarkAHref
}
node.Tokens = bytes.ReplaceAll(node.Tokens, []byte(oldDest), []byte(dest))
} else if ast.NodeAttributeView == node.Type {
needWrite := false