瀏覽代碼

:bug: 文档导出为图片时图片地址不正确 Fix https://github.com/siyuan-note/siyuan/issues/6925

Liang Ding 2 年之前
父節點
當前提交
608bce58a6
共有 3 個文件被更改,包括 9 次插入4 次删除
  1. 1 0
      app/src/protyle/export/util.ts
  2. 6 2
      kernel/api/export.go
  3. 2 2
      kernel/model/export.go

+ 1 - 0
app/src/protyle/export/util.ts

@@ -45,6 +45,7 @@ export const exportImage = (id: string) => {
     fetchPost("/api/export/exportPreviewHTML", {
         id,
         keepFold: false,
+        image: true,
     }, (response) => {
         const previewElement = exportDialog.element.querySelector("#preview");
         previewElement.innerHTML = response.data.content;

+ 6 - 2
kernel/api/export.go

@@ -240,7 +240,11 @@ func exportPreviewHTML(c *gin.Context) {
 	if nil != arg["merge"] {
 		merge = arg["merge"].(bool)
 	}
-	name, content := model.ExportHTML(id, "", true, keepFold, merge)
+	image := false
+	if nil != arg["image"] {
+		image = arg["image"].(bool)
+	}
+	name, content := model.ExportHTML(id, "", true, image, keepFold, merge)
 	// 导出 PDF 预览时点击块引转换后的脚注跳转不正确 https://github.com/siyuan-note/siyuan/issues/5894
 	content = strings.ReplaceAll(content, "http://"+util.LocalHost+":"+util.ServerPort+"/#", "#")
 
@@ -271,7 +275,7 @@ func exportHTML(c *gin.Context) {
 	if nil != arg["merge"] {
 		merge = arg["merge"].(bool)
 	}
-	name, content := model.ExportHTML(id, savePath, pdf, keepFold, merge)
+	name, content := model.ExportHTML(id, savePath, pdf, false, keepFold, merge)
 	ret.Data = map[string]interface{}{
 		"id":      id,
 		"name":    name,

+ 2 - 2
kernel/model/export.go

@@ -339,7 +339,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
 	return
 }
 
-func ExportHTML(id, savePath string, pdf, keepFold, merge bool) (name, dom string) {
+func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, dom string) {
 	savePath = strings.TrimSpace(savePath)
 	tree, _ := loadTreeByBlockID(id)
 
@@ -438,7 +438,7 @@ func ExportHTML(id, savePath string, pdf, keepFold, merge bool) (name, dom strin
 				return
 			}
 		}
-	} else { // 导出 PDF 需要将资源文件路径改为 HTTP 伺服
+	} else if pdf && !image { // 导出 PDF 需要将资源文件路径改为 HTTP 伺服
 		luteEngine.RenderOptions.LinkBase = "http://" + util.LocalHost + ":" + util.ServerPort + "/"
 	}