🎨 导出 PDF 时块引转换脚注使用书签跳转 https://github.com/siyuan-note/siyuan/issues/5761

This commit is contained in:
Liang Ding 2022-08-30 16:53:21 +08:00
parent a807e47d63
commit 150ebe2d1a
No known key found for this signature in database
GPG key ID: 136F30F901A2231D

View file

@ -352,6 +352,26 @@ func ExportHTML(id, savePath string, pdf bool) (name, dom string) {
}
tree = exportTree(tree, true)
//if pdf { // TODO: 导出 PDF 时块引转换脚注使用书签跳转 https://github.com/siyuan-note/siyuan/issues/5761
// var footnotesDefs []*ast.Node
// ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
// if entering && ast.NodeFootnotesDef == n.Type {
// footnotesDefs = append(footnotesDefs, n)
// }
// return ast.WalkContinue
// })
// for _, f := range footnotesDefs {
// link := &ast.Node{Type: ast.NodeLink}
// link.AppendChild(&ast.Node{Type: ast.NodeOpenBracket})
// link.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(" ")})
// link.AppendChild(&ast.Node{Type: ast.NodeCloseBracket})
// link.AppendChild(&ast.Node{Type: ast.NodeOpenParen})
// link.AppendChild(&ast.Node{Type: ast.NodeLinkDest, Tokens: []byte("pdf-outline://footnotes-def-" + f.FootnotesRefId)})
// link.AppendChild(&ast.Node{Type: ast.NodeCloseParen})
// f.PrependChild(link)
// }
//}
name = path.Base(tree.Path)
name = util.FilterFileName(name) // 导出 PDF、HTML 和 Word 时未移除不支持的文件名符号 https://github.com/siyuan-note/siyuan/issues/5614
@ -469,8 +489,19 @@ func AddPDFOutline(id, p string) (err error) {
})
bms := map[string]*pdfcpu.Bookmark{}
footnotes := map[string]*pdfcpu.Bookmark{}
for _, link := range links {
linkID := link.URI[strings.LastIndex(link.URI, "/")+1:]
//if strings.HasPrefix(linkID, "footnotes-def-") { // 导出 PDF 时块引转换脚注使用书签跳转 https://github.com/siyuan-note/siyuan/issues/5761
// footnotes[linkID] = &pdfcpu.Bookmark{
// Title: "Footnote [^" + linkID + "]",
// PageFrom: link.Page,
// AbsPos: link.Rect.UR.Y,
// Level: 7,
// }
// continue
//}
title := sql.GetBlock(linkID).Content
title, _ = url.QueryUnescape(title)
bm := &pdfcpu.Bookmark{
@ -481,7 +512,7 @@ func AddPDFOutline(id, p string) (err error) {
bms[linkID] = bm
}
if 1 > len(bms) {
if 1 > len(bms) && 1 > len(footnotes) {
return
}
@ -525,6 +556,17 @@ func AddPDFOutline(id, p string) (err error) {
}
}
//if 4 == Conf.Export.BlockRefMode { // 块引转脚注
// var footnotesBms []*pdfcpu.Bookmark
// for _, bm := range footnotes {
// footnotesBms = append(footnotesBms, bm)
// }
// sort.Slice(footnotesBms, func(i, j int) bool { return footnotesBms[i].PageFrom < footnotesBms[j].PageFrom })
// for _, bm := range footnotesBms {
// topBms = append(topBms, bm)
// }
//}
outFile := inFile + ".tmp"
err = api.AddBookmarksFile(inFile, outFile, topBms, nil)
if nil != err {