Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
af03c658f0
3 changed files with 39 additions and 28 deletions
|
@ -1104,21 +1104,21 @@ func assetsLinkDestsInNode(node *ast.Node) (ret []string) {
|
|||
}
|
||||
|
||||
if ast.NodeLinkDest == n.Type {
|
||||
if !isRelativePath(n.Tokens) {
|
||||
if !treenode.IsRelativePath(n.Tokens) {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
dest := strings.TrimSpace(string(n.Tokens))
|
||||
ret = append(ret, dest)
|
||||
} else if n.IsTextMarkType("a") {
|
||||
if !isRelativePath(gulu.Str.ToBytes(n.TextMarkAHref)) {
|
||||
if !treenode.IsRelativePath(gulu.Str.ToBytes(n.TextMarkAHref)) {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
dest := strings.TrimSpace(n.TextMarkAHref)
|
||||
ret = append(ret, dest)
|
||||
} else if n.IsTextMarkType("file-annotation-ref") {
|
||||
if !isRelativePath(gulu.Str.ToBytes(n.TextMarkFileAnnotationRefID)) {
|
||||
if !treenode.IsRelativePath(gulu.Str.ToBytes(n.TextMarkFileAnnotationRefID)) {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
|
@ -1136,24 +1136,14 @@ func assetsLinkDestsInNode(node *ast.Node) (ret []string) {
|
|||
// 兼容两种属性名 custom-data-assets 和 data-assets https://github.com/siyuan-note/siyuan/issues/4122#issuecomment-1154796568
|
||||
dataAssets = n.IALAttr("data-assets")
|
||||
}
|
||||
if "" == dataAssets || !isRelativePath([]byte(dataAssets)) {
|
||||
if "" == dataAssets || !treenode.IsRelativePath([]byte(dataAssets)) {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
ret = append(ret, dataAssets)
|
||||
} else { // HTMLBlock/InlineHTML/IFrame/Audio/Video
|
||||
if index := bytes.Index(n.Tokens, []byte("src=\"")); 0 < index {
|
||||
src := n.Tokens[index+len("src=\""):]
|
||||
if index = bytes.Index(src, []byte("\"")); 0 < index {
|
||||
src = src[:bytes.Index(src, []byte("\""))]
|
||||
if !isRelativePath(src) {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
dest := strings.TrimSpace(string(src))
|
||||
ret = append(ret, dest)
|
||||
} else {
|
||||
logging.LogWarnf("src is missing the closing double quote in tree [%s] ", node.Box+node.Path)
|
||||
}
|
||||
dest := treenode.GetNodeSrcTokens(n)
|
||||
if "" != dest {
|
||||
ret = append(ret, dest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1169,16 +1159,6 @@ func assetsLinkDestsInNode(node *ast.Node) (ret []string) {
|
|||
return
|
||||
}
|
||||
|
||||
func isRelativePath(dest []byte) bool {
|
||||
if 1 > len(dest) {
|
||||
return false
|
||||
}
|
||||
if '/' == dest[0] {
|
||||
return false
|
||||
}
|
||||
return !bytes.Contains(dest, []byte(":"))
|
||||
}
|
||||
|
||||
// allAssetAbsPaths 返回 asset 相对路径(assets/xxx)到绝对路径(F:\SiYuan\data\assets\xxx)的映射。
|
||||
func allAssetAbsPaths() (assetsAbsPathMap map[string]string, err error) {
|
||||
notebooks, err := ListNotebooks()
|
||||
|
|
|
@ -1620,7 +1620,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|||
case av.KeyTypeMAsset: // 导出资源文件列 https://github.com/siyuan-note/siyuan/issues/9919
|
||||
for _, value := range keyValues.Values {
|
||||
for _, asset := range value.MAsset {
|
||||
if !isRelativePath([]byte(asset.Content)) {
|
||||
if !treenode.IsRelativePath([]byte(asset.Content)) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -283,6 +283,9 @@ func NodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATi
|
|||
buf.WriteByte(lex.ItemBackslash)
|
||||
case ast.NodeBackslashContent:
|
||||
buf.Write(n.Tokens)
|
||||
case ast.NodeAudio, ast.NodeVideo:
|
||||
buf.WriteString(GetNodeSrcTokens(n))
|
||||
buf.WriteByte(' ')
|
||||
}
|
||||
lastSpace = false
|
||||
return ast.WalkContinue
|
||||
|
@ -293,6 +296,34 @@ func NodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATi
|
|||
return buf.String()
|
||||
}
|
||||
|
||||
func GetNodeSrcTokens(n *ast.Node) (ret string) {
|
||||
if index := bytes.Index(n.Tokens, []byte("src=\"")); 0 < index {
|
||||
src := n.Tokens[index+len("src=\""):]
|
||||
if index = bytes.Index(src, []byte("\"")); 0 < index {
|
||||
src = src[:bytes.Index(src, []byte("\""))]
|
||||
if !IsRelativePath(src) {
|
||||
return
|
||||
}
|
||||
|
||||
ret = strings.TrimSpace(string(src))
|
||||
return
|
||||
}
|
||||
|
||||
logging.LogWarnf("src is missing the closing double quote in tree [%s] ", n.Box+n.Path)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func IsRelativePath(dest []byte) bool {
|
||||
if 1 > len(dest) {
|
||||
return false
|
||||
}
|
||||
if '/' == dest[0] {
|
||||
return false
|
||||
}
|
||||
return !bytes.Contains(dest, []byte(":"))
|
||||
}
|
||||
|
||||
func FirstLeafBlock(node *ast.Node) (ret *ast.Node) {
|
||||
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering || n.IsMarker() {
|
||||
|
|
Loading…
Add table
Reference in a new issue