🐛 Unable to search audio, video blocks by asset path https://github.com/siyuan-note/siyuan/issues/10468

This commit is contained in:
Daniel 2024-02-28 21:08:46 +08:00
parent 1a5355ce27
commit 8d9eafbfd8
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 39 additions and 28 deletions

View file

@ -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() {