From 150ebe2d1a9d3c4bbcae2afb00651ed08722bdfc Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Tue, 30 Aug 2022 16:53:21 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E5=AF=BC=E5=87=BA=20PDF=20=E6=97=B6?= =?UTF-8?q?=E5=9D=97=E5=BC=95=E8=BD=AC=E6=8D=A2=E8=84=9A=E6=B3=A8=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E4=B9=A6=E7=AD=BE=E8=B7=B3=E8=BD=AC=20https://github.?= =?UTF-8?q?com/siyuan-note/siyuan/issues/5761?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/export.go | 44 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/kernel/model/export.go b/kernel/model/export.go index c2d26b681..2f65c7f9c 100644 --- a/kernel/model/export.go +++ b/kernel/model/export.go @@ -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 {