Browse Source

Merge remote-tracking branch 'origin/dev' into dev

Vanessa 2 years ago
parent
commit
26ea14341d

+ 1 - 0
app/appearance/langs/en_US.json

@@ -107,6 +107,7 @@
   "exportPDF2": "Page margins",
   "exportPDF3": "Page Scale",
   "exportPDF4": "Remove assets directory",
+  "exportPDF5": "Keep folded",
   "upload": "Upload",
   "reminderTip": "The reminder time cannot be less than the current time",
   "wechatTip": "The content block will be sent to the cloud in clear text, and pushed through the WeChat MP template message when it expires",

+ 1 - 0
app/appearance/langs/es_ES.json

@@ -107,6 +107,7 @@
   "exportPDF2": "Márgenes de la página",
   "exportPDF3": "Escala de la página",
   "exportPDF4": "Eliminar directorio de activos",
+  "exportPDF5": "Mantener doblado",
   "upload": "Subir",
   "reminderTip": "La hora del recordatorio no puede ser inferior a la hora actual",
   "wechatTip": "El bloque de contenido se enviará a la nube en texto claro, y se empujará a través del mensaje de plantilla de WeChat MP cuando caduque",

+ 1 - 0
app/appearance/langs/fr_FR.json

@@ -107,6 +107,7 @@
   "exportPDF2": "Marges de page",
   "exportPDF3": "Échelle de page",
   "exportPDF4": "Supprimer le répertoire des actifs",
+  "exportPDF5": "Garder plié",
   "upload": "Télécharger",
   "reminderTip": "The reminder time cannot be less than the current time",
   "wechatTip": "Le bloc de contenu sera envoyé au cloud en texte clair et transmis au message du modèle de compte officiel WeChat à son expiration.",

+ 1 - 0
app/appearance/langs/zh_CHT.json

@@ -107,6 +107,7 @@
   "exportPDF2": "頁面邊距",
   "exportPDF3": "頁面縮放",
   "exportPDF4": "移除 assets 目錄",
+  "exportPDF5": "保持折疊狀態",
   "upload": "上傳",
   "reminderTip": "提醒時間不能小於當前時間",
   "wechatTip": "該內容塊將以明文形式發送到雲端,到期時通過微信公眾號模板消息進行推送",

+ 1 - 0
app/appearance/langs/zh_CN.json

@@ -107,6 +107,7 @@
   "exportPDF2": "页面边距",
   "exportPDF3": "页面缩放",
   "exportPDF4": "移除 assets 目录",
+  "exportPDF5": "保持折叠状态",
   "upload": "上传",
   "reminderTip": "提醒时间不能小于当前时间",
   "wechatTip": "该内容块将以明文形式发送到云端,到期时通过微信公众号模板消息进行推送",

+ 6 - 2
kernel/api/export.go

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

+ 13 - 10
kernel/model/export.go

@@ -196,7 +196,7 @@ func exportData(exportFolder string) (err error) {
 
 func Preview(id string) string {
 	tree, _ := loadTreeByBlockID(id)
-	tree = exportTree(tree, false, false)
+	tree = exportTree(tree, false, false, false)
 	luteEngine := NewLute()
 	luteEngine.SetFootnotes(true)
 	md := treenode.FormatNode(tree.Root, luteEngine)
@@ -250,7 +250,7 @@ func ExportDocx(id, savePath string, removeAssets bool) (err error) {
 func ExportMarkdownHTML(id, savePath string, docx bool) (name, dom string) {
 	tree, _ := loadTreeByBlockID(id)
 
-	tree = exportTree(tree, true, true)
+	tree = exportTree(tree, true, true, false)
 	name = path.Base(tree.HPath)
 	name = util.FilterFileName(name) // 导出 PDF、HTML 和 Word 时未移除不支持的文件名符号 https://github.com/siyuan-note/siyuan/issues/5614
 
@@ -338,7 +338,7 @@ func ExportMarkdownHTML(id, savePath string, docx bool) (name, dom string) {
 	return
 }
 
-func ExportHTML(id, savePath string, pdf bool) (name, dom string) {
+func ExportHTML(id, savePath string, pdf, keepFold bool) (name, dom string) {
 	tree, _ := loadTreeByBlockID(id)
 	var headings []*ast.Node
 	if pdf { // 导出 PDF 需要标记目录书签
@@ -362,7 +362,7 @@ func ExportHTML(id, savePath string, pdf bool) (name, dom string) {
 		}
 	}
 
-	tree = exportTree(tree, true, true)
+	tree = exportTree(tree, true, true, keepFold)
 	//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 {
@@ -600,7 +600,7 @@ func AddPDFOutline(id, p string) (err error) {
 
 func CopyStdMarkdown(id string) string {
 	tree, _ := loadTreeByBlockID(id)
-	tree = exportTree(tree, false, false)
+	tree = exportTree(tree, false, false, false)
 	luteEngine := NewLute()
 	luteEngine.SetFootnotes(true)
 	luteEngine.SetKramdownIAL(false)
@@ -967,7 +967,7 @@ func ExportMarkdownContent(id string) (hPath, exportedMd string) {
 func exportMarkdownContent(id string) (hPath, exportedMd string) {
 	tree, _ := loadTreeByBlockID(id)
 	hPath = tree.HPath
-	tree = exportTree(tree, false, true)
+	tree = exportTree(tree, false, true, false)
 	luteEngine := NewLute()
 	luteEngine.SetFootnotes(true)
 	luteEngine.SetKramdownIAL(false)
@@ -1032,7 +1032,7 @@ func processKaTexMacros(n *ast.Node) {
 	}
 }
 
-func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros bool) (ret *parse.Tree) {
+func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros, keepFold bool) (ret *parse.Tree) {
 	luteEngine := NewLute()
 	ret = tree
 	id := tree.Root.ID
@@ -1244,9 +1244,12 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros bool) (ret *parse.T
 			return ast.WalkContinue
 		}
 
-		// 块折叠以后导出 HTML/PDF 固定展开 https://github.com/siyuan-note/siyuan/issues/4064
-		n.RemoveIALAttr("fold")
-		n.RemoveIALAttr("heading-fold")
+		// 支持按照现有折叠状态导出 PDF https://github.com/siyuan-note/siyuan/issues/5941
+		if !keepFold {
+			// 块折叠以后导出 HTML/PDF 固定展开 https://github.com/siyuan-note/siyuan/issues/4064
+			n.RemoveIALAttr("fold")
+			n.RemoveIALAttr("heading-fold")
+		}
 
 		if ast.NodeParagraph == n.Type {
 			if nil == n.FirstChild {