mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-18 10:00:48 +08:00
This commit is contained in:
parent
f2b2079972
commit
1fcf79b859
@ -26,7 +26,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/88250/lute"
|
|
||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
"github.com/emirpasic/gods/sets/hashset"
|
"github.com/emirpasic/gods/sets/hashset"
|
||||||
@ -279,17 +278,87 @@ func GetBacklinkDoc(defID, refTreeID string) (ret []*Backlink) {
|
|||||||
logging.LogErrorf("load ref tree [%s] failed: %s", refTreeID, err)
|
logging.LogErrorf("load ref tree [%s] failed: %s", refTreeID, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
linkPaths := toSubTree(linkRefs, keyword)
|
|
||||||
for _, link := range linkPaths {
|
for _, linkRef := range linkRefs {
|
||||||
for _, c := range link.Children {
|
n := treenode.GetNodeInTree(refTree, linkRef.ID)
|
||||||
n := treenode.GetNodeInTree(refTree, c.ID)
|
if nil == n {
|
||||||
dom := lute.RenderNodeBlockDOM(n, luteEngine.ParseOptions, luteEngine.RenderOptions)
|
continue
|
||||||
ret = append(ret, &Backlink{
|
|
||||||
DOM: dom,
|
|
||||||
BlockPaths: buildBlockBreadcrumb(n),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var renderNodes []*ast.Node
|
||||||
|
if ast.NodeListItem == n.Type {
|
||||||
|
if nil == n.FirstChild {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
c := n.FirstChild
|
||||||
|
if 3 == n.ListData.Typ {
|
||||||
|
c = n.FirstChild.Next
|
||||||
|
}
|
||||||
|
|
||||||
|
expand := true
|
||||||
|
for liFirstBlockSpan := c.FirstChild; nil != liFirstBlockSpan; liFirstBlockSpan = liFirstBlockSpan.Next {
|
||||||
|
if treenode.IsBlockRef(liFirstBlockSpan) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if "" != strings.TrimSpace(liFirstBlockSpan.Text()) {
|
||||||
|
expand = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
renderNodes = append(renderNodes, n)
|
||||||
|
if !expand {
|
||||||
|
var unlinks []*ast.Node
|
||||||
|
for cc := c.Next; nil != cc; cc = cc.Next {
|
||||||
|
unlinks = append(unlinks, cc)
|
||||||
|
}
|
||||||
|
for _, unlink := range unlinks {
|
||||||
|
unlink.Unlink()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ast.NodeHeading == n.Type {
|
||||||
|
c := n.FirstChild
|
||||||
|
if nil == c {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
expand := true
|
||||||
|
for headingFirstSpan := c; nil != headingFirstSpan; headingFirstSpan = headingFirstSpan.Next {
|
||||||
|
if treenode.IsBlockRef(headingFirstSpan) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if "" != strings.TrimSpace(headingFirstSpan.Text()) {
|
||||||
|
expand = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
renderNodes = append(renderNodes, n)
|
||||||
|
if !expand {
|
||||||
|
var unlinks []*ast.Node
|
||||||
|
for cc := n.Next; nil != cc; cc = cc.Next {
|
||||||
|
unlinks = append(unlinks, cc)
|
||||||
|
}
|
||||||
|
for _, unlink := range unlinks {
|
||||||
|
unlink.Unlink()
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
cc := treenode.HeadingChildren(n)
|
||||||
|
renderNodes = append(renderNodes, cc...)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
renderNodes = append(renderNodes, n)
|
||||||
|
}
|
||||||
|
|
||||||
|
dom := renderBlockDOMByNodes(renderNodes, luteEngine)
|
||||||
|
ret = append(ret, &Backlink{
|
||||||
|
DOM: dom,
|
||||||
|
BlockPaths: buildBlockBreadcrumb(n),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user