Skip to content

Commit

Permalink
🎨 Improve list item, super block and blockquote backlink propagation #…
Browse files Browse the repository at this point in the history
88250 committed Jan 11, 2025
1 parent 58c2579 commit 1d77cde
Showing 2 changed files with 26 additions and 3 deletions.
27 changes: 25 additions & 2 deletions kernel/model/backlink.go
Original file line number Diff line number Diff line change
@@ -588,18 +588,41 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keywords []string) (ret []
sqlParagraphParents := sql.GetBlocks(paragraphParentIDs)
paragraphParents := fromSQLBlocks(&sqlParagraphParents, "", 12)

luteEngine := util.NewLute()
originalRefBlockIDs = map[string]string{}
processedParagraphs := hashset.New()
for _, parent := range paragraphParents {
if "NodeListItem" == parent.Type || "NodeBlockquote" == parent.Type || "NodeSuperBlock" == parent.Type {
paragraphUseParentLi := true
if refBlock := parentRefParagraphs[parent.ID]; nil != refBlock {
processedParagraphs.Add(parent.ID)
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)
}

originalRefBlockIDs[parent.ID] = refBlock.ID
if !matchBacklinkKeyword(parent, keywords) {
refsCount--
continue
}
ret = append(ret, parent)

if paragraphUseParentLi {
ret = append(ret, parent)
}
}
}
}
2 changes: 1 addition & 1 deletion kernel/treenode/node.go
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ func IsBlockRef(n *ast.Node) bool {
if nil == n {
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 {

0 comments on commit 1d77cde

Please sign in to comment.