From 84244f4fc767531b108dab51c56cb087814f78b0 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 12 Apr 2023 12:20:00 +0800 Subject: [PATCH] :art: Asset files no longer use HTTP server when exporting PDF https://github.com/siyuan-note/siyuan/issues/7965 --- kernel/model/export.go | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/kernel/model/export.go b/kernel/model/export.go index 55eedcac4..8509e0266 100644 --- a/kernel/model/export.go +++ b/kernel/model/export.go @@ -592,8 +592,6 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do return } } - } else if pdf && !image { // 导出 PDF 需要将资源文件路径改为 HTTP 伺服 - luteEngine.RenderOptions.LinkBase = "http://" + util.LocalHost + ":" + util.ServerPort + "/" } if pdf { @@ -685,23 +683,12 @@ func ProcessPDF(id, p string, merge, removeAssets bool) (err error) { } var headings []*ast.Node - var assetDests []string + assetDests := assetsLinkDestsInTree(tree) ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus { if !entering { return ast.WalkContinue } - if n.IsTextMarkType("a") { - dest := n.TextMarkAHref - if util.IsAssetLinkDest([]byte(dest)) { - assetDests = append(assetDests, dest) - } - } else if ast.NodeLinkDest == n.Type { - if util.IsAssetLinkDest(n.Tokens) { - assetDests = append(assetDests, string(n.Tokens)) - } - } - if ast.NodeHeading == n.Type && !n.ParentIs(ast.NodeBlockquote) { headings = append(headings, n) return ast.WalkSkipChildren @@ -833,6 +820,9 @@ func processPDFLinkEmbedAssets(pdfCtx *pdfcpu.Context, assetDests []string, remo for _, link := range assetLinks { link.URI = strings.ReplaceAll(link.URI, "http://"+util.LocalHost+":"+util.ServerPort+"/export/temp/", "") link.URI, _ = url.PathUnescape(link.URI) + if idx := strings.Index(link.URI, "?"); 0 < idx { + link.URI = link.URI[:idx] + } if !removeAssets { // 不移除资源文件夹的话将超链接指向资源文件夹