🎨 Improve list item, super block and blockquote backlink propagation https://github.com/siyuan-note/siyuan/issues/13776

This commit is contained in:
Daniel 2025-01-11 12:24:16 +08:00
parent 58c257960b
commit 1d77cdefc2
No known key found for this signature in database
GPG Key ID: 86211BA83DF03017
2 changed files with 26 additions and 3 deletions

View File

@ -588,21 +588,44 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keywords []string) (ret []
sqlParagraphParents := sql.GetBlocks(paragraphParentIDs) sqlParagraphParents := sql.GetBlocks(paragraphParentIDs)
paragraphParents := fromSQLBlocks(&sqlParagraphParents, "", 12) paragraphParents := fromSQLBlocks(&sqlParagraphParents, "", 12)
luteEngine := util.NewLute()
originalRefBlockIDs = map[string]string{} originalRefBlockIDs = map[string]string{}
processedParagraphs := hashset.New() processedParagraphs := hashset.New()
for _, parent := range paragraphParents { for _, parent := range paragraphParents {
if "NodeListItem" == parent.Type || "NodeBlockquote" == parent.Type || "NodeSuperBlock" == parent.Type { if "NodeListItem" == parent.Type || "NodeBlockquote" == parent.Type || "NodeSuperBlock" == parent.Type {
paragraphUseParentLi := true
if refBlock := parentRefParagraphs[parent.ID]; nil != refBlock { if refBlock := parentRefParagraphs[parent.ID]; nil != refBlock {
if "NodeListItem" == parent.Type && parent.FContent != refBlock.Content {
if inlineTree := parse.Inline("", []byte(refBlock.Markdown), luteEngine.ParseOptions); nil != inlineTree {
for c := inlineTree.Root.FirstChild.FirstChild; c != nil; c = c.Next {
if treenode.IsBlockRef(c) {
continue
}
if "" != strings.TrimSpace(c.Text()) {
paragraphUseParentLi = false
break
}
}
}
}
if paragraphUseParentLi {
processedParagraphs.Add(parent.ID) processedParagraphs.Add(parent.ID)
}
originalRefBlockIDs[parent.ID] = refBlock.ID originalRefBlockIDs[parent.ID] = refBlock.ID
if !matchBacklinkKeyword(parent, keywords) { if !matchBacklinkKeyword(parent, keywords) {
refsCount-- refsCount--
continue continue
} }
if paragraphUseParentLi {
ret = append(ret, parent) ret = append(ret, parent)
} }
} }
} }
}
for _, link := range links { for _, link := range links {
for _, ref := range link.Refs { for _, ref := range link.Refs {
if "NodeParagraph" == ref.Type { if "NodeParagraph" == ref.Type {

View File

@ -100,7 +100,7 @@ func IsBlockRef(n *ast.Node) bool {
if nil == n { if nil == n {
return false return false
} }
return ast.NodeTextMark == n.Type && n.IsTextMarkType("block-ref") return (ast.NodeTextMark == n.Type && n.IsTextMarkType("block-ref")) || ast.NodeBlockRef == n.Type
} }
func IsBlockLink(n *ast.Node) bool { func IsBlockLink(n *ast.Node) bool {