From 6560b0ce9672f76a4dd4c8d77ef1c1eb41654e0e Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 23 Sep 2022 21:44:15 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20PDF=20=E6=A0=87=E6=B3=A8=E9=A2=84?= =?UTF-8?q?=E8=A7=88=E5=A4=B1=E6=95=88=20Fix=20https://github.com/siyuan-n?= =?UTF-8?q?ote/siyuan/issues/5934?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/sql/database.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/kernel/sql/database.go b/kernel/sql/database.go index 3cd38af35..45037f38d 100644 --- a/kernel/sql/database.go +++ b/kernel/sql/database.go @@ -300,6 +300,34 @@ func refsFromTree(tree *parse.Tree) (refs []*Ref, fileAnnotationRefs []*FileAnno Type: treenode.TypeAbbr(n.Type.String()), } fileAnnotationRefs = append(fileAnnotationRefs, ref) + } else if ast.NodeTextMark == n.Type && n.IsTextMarkType("file-annotation-ref") { + pathID := n.TextMarkFileAnnotationRefID + idx := strings.LastIndex(pathID, "/") + if -1 == idx { + return ast.WalkContinue + } + + filePath := pathID[:idx] + annotationID := pathID[idx+1:] + + anchor := n.TextMarkTextContent + text := filePath + if "" != anchor { + text = anchor + } + parentBlock := treenode.ParentBlock(n) + ref := &FileAnnotationRef{ + ID: ast.NewNodeID(), + FilePath: filePath, + AnnotationID: annotationID, + BlockID: parentBlock.ID, + RootID: tree.ID, + Box: tree.Box, + Path: tree.Path, + Content: text, + Type: treenode.TypeAbbr(n.Type.String()), + } + fileAnnotationRefs = append(fileAnnotationRefs, ref) } return ast.WalkContinue })