Skip to content

Commit

Permalink
🎨 Improve page number for exporting PDF annotation hyperlinks #11780
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jun 24, 2024
1 parent a88440a commit c896d96
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions kernel/model/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ func ExportResources(resourcePaths []string, mainName string) (exportFilePath st

func Preview(id string) (retStdHTML string, retOutline []*Path) {
tree, _ := LoadTreeByBlockID(id)
tree = exportTree(tree, false, false, true,
tree = exportTree(tree, false, false,
Conf.Export.BlockRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode,
Conf.Export.TagOpenMarker, Conf.Export.TagCloseMarker,
Conf.Export.BlockRefTextLeft, Conf.Export.BlockRefTextRight,
Expand Down Expand Up @@ -640,7 +640,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
}
}

tree = exportTree(tree, true, false, !docx,
tree = exportTree(tree, true, false,
Conf.Export.BlockRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode,
Conf.Export.TagOpenMarker, Conf.Export.TagCloseMarker,
Conf.Export.BlockRefTextLeft, Conf.Export.BlockRefTextRight,
Expand Down Expand Up @@ -790,7 +790,7 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do
}
}

tree = exportTree(tree, true, keepFold, true,
tree = exportTree(tree, true, keepFold,
Conf.Export.BlockRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode,
Conf.Export.TagOpenMarker, Conf.Export.TagCloseMarker,
Conf.Export.BlockRefTextLeft, Conf.Export.BlockRefTextRight,
Expand Down Expand Up @@ -1837,7 +1837,7 @@ func exportMarkdownContent0(tree *parse.Tree, cloudAssetsBase string, assetsDest
blockRefTextLeft, blockRefTextRight string,
addTitle bool,
defBlockIDs []string) (ret string) {
tree = exportTree(tree, false, false, true,
tree = exportTree(tree, false, false,
blockRefMode, blockEmbedMode, fileAnnotationRefMode,
tagOpenMarker, tagCloseMarker,
blockRefTextLeft, blockRefTextRight,
Expand Down Expand Up @@ -1926,7 +1926,7 @@ func exportMarkdownContent0(tree *parse.Tree, cloudAssetsBase string, assetsDest
return
}

func exportTree(tree *parse.Tree, wysiwyg, keepFold, pdfPageNum bool,
func exportTree(tree *parse.Tree, wysiwyg, keepFold bool,
blockRefMode, blockEmbedMode, fileAnnotationRefMode int,
tagOpenMarker, tagCloseMarker string,
blockRefTextLeft, blockRefTextRight string,
Expand Down Expand Up @@ -1975,7 +1975,7 @@ func exportTree(tree *parse.Tree, wysiwyg, keepFold, pdfPageNum bool,
return ast.WalkSkipChildren
}

status := processFileAnnotationRef(refID, n, fileAnnotationRefMode, pdfPageNum)
status := processFileAnnotationRef(refID, n, fileAnnotationRefMode)
unlinks = append(unlinks, n)
return status
} else if n.IsTextMarkType("tag") {
Expand Down Expand Up @@ -2551,7 +2551,7 @@ func exportRefTrees0(tree *parse.Tree, retTrees *map[string]*parse.Tree) {
})
}

func processFileAnnotationRef(refID string, n *ast.Node, fileAnnotationRefMode int, pdfPageNum bool) ast.WalkStatus {
func processFileAnnotationRef(refID string, n *ast.Node, fileAnnotationRefMode int) ast.WalkStatus {
p := refID[:strings.LastIndex(refID, "/")]
absPath, err := GetAssetAbsPath(p)
if nil != err {
Expand Down Expand Up @@ -2591,10 +2591,7 @@ func processFileAnnotationRef(refID string, n *ast.Node, fileAnnotationRefMode i
}
fileAnnotationRefLink.AppendChild(&ast.Node{Type: ast.NodeCloseBracket})
fileAnnotationRefLink.AppendChild(&ast.Node{Type: ast.NodeOpenParen})
dest := p
if pdfPageNum {
dest += "?p=" + pageStr
}
dest := p + "#page=" + pageStr // https://github.com/siyuan-note/siyuan/issues/11780
fileAnnotationRefLink.AppendChild(&ast.Node{Type: ast.NodeLinkDest, Tokens: []byte(dest)})
fileAnnotationRefLink.AppendChild(&ast.Node{Type: ast.NodeCloseParen})
n.InsertBefore(fileAnnotationRefLink)
Expand Down

0 comments on commit c896d96

Please sign in to comment.