mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 08:30:42 +02:00
🎨 导出 PDF 支持保留折叠状态 https://github.com/siyuan-note/siyuan/issues/5941
This commit is contained in:
parent
2c2bd2a379
commit
11a580916c
7 changed files with 24 additions and 12 deletions
|
@ -107,6 +107,7 @@
|
||||||
"exportPDF2": "Page margins",
|
"exportPDF2": "Page margins",
|
||||||
"exportPDF3": "Page Scale",
|
"exportPDF3": "Page Scale",
|
||||||
"exportPDF4": "Remove assets directory",
|
"exportPDF4": "Remove assets directory",
|
||||||
|
"exportPDF5": "Keep folded",
|
||||||
"upload": "Upload",
|
"upload": "Upload",
|
||||||
"reminderTip": "The reminder time cannot be less than the current time",
|
"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",
|
"wechatTip": "The content block will be sent to the cloud in clear text, and pushed through the WeChat MP template message when it expires",
|
||||||
|
|
|
@ -107,6 +107,7 @@
|
||||||
"exportPDF2": "Márgenes de la página",
|
"exportPDF2": "Márgenes de la página",
|
||||||
"exportPDF3": "Escala de la página",
|
"exportPDF3": "Escala de la página",
|
||||||
"exportPDF4": "Eliminar directorio de activos",
|
"exportPDF4": "Eliminar directorio de activos",
|
||||||
|
"exportPDF5": "Mantener doblado",
|
||||||
"upload": "Subir",
|
"upload": "Subir",
|
||||||
"reminderTip": "La hora del recordatorio no puede ser inferior a la hora actual",
|
"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",
|
"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",
|
||||||
|
|
|
@ -107,6 +107,7 @@
|
||||||
"exportPDF2": "Marges de page",
|
"exportPDF2": "Marges de page",
|
||||||
"exportPDF3": "Échelle de page",
|
"exportPDF3": "Échelle de page",
|
||||||
"exportPDF4": "Supprimer le répertoire des actifs",
|
"exportPDF4": "Supprimer le répertoire des actifs",
|
||||||
|
"exportPDF5": "Garder plié",
|
||||||
"upload": "Télécharger",
|
"upload": "Télécharger",
|
||||||
"reminderTip": "The reminder time cannot be less than the current time",
|
"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.",
|
"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.",
|
||||||
|
|
|
@ -107,6 +107,7 @@
|
||||||
"exportPDF2": "頁面邊距",
|
"exportPDF2": "頁面邊距",
|
||||||
"exportPDF3": "頁面縮放",
|
"exportPDF3": "頁面縮放",
|
||||||
"exportPDF4": "移除 assets 目錄",
|
"exportPDF4": "移除 assets 目錄",
|
||||||
|
"exportPDF5": "保持折疊狀態",
|
||||||
"upload": "上傳",
|
"upload": "上傳",
|
||||||
"reminderTip": "提醒時間不能小於當前時間",
|
"reminderTip": "提醒時間不能小於當前時間",
|
||||||
"wechatTip": "該內容塊將以明文形式發送到雲端,到期時通過微信公眾號模板消息進行推送",
|
"wechatTip": "該內容塊將以明文形式發送到雲端,到期時通過微信公眾號模板消息進行推送",
|
||||||
|
|
|
@ -107,6 +107,7 @@
|
||||||
"exportPDF2": "页面边距",
|
"exportPDF2": "页面边距",
|
||||||
"exportPDF3": "页面缩放",
|
"exportPDF3": "页面缩放",
|
||||||
"exportPDF4": "移除 assets 目录",
|
"exportPDF4": "移除 assets 目录",
|
||||||
|
"exportPDF5": "保持折叠状态",
|
||||||
"upload": "上传",
|
"upload": "上传",
|
||||||
"reminderTip": "提醒时间不能小于当前时间",
|
"reminderTip": "提醒时间不能小于当前时间",
|
||||||
"wechatTip": "该内容块将以明文形式发送到云端,到期时通过微信公众号模板消息进行推送",
|
"wechatTip": "该内容块将以明文形式发送到云端,到期时通过微信公众号模板消息进行推送",
|
||||||
|
|
|
@ -194,7 +194,7 @@ func exportPreviewHTML(c *gin.Context) {
|
||||||
|
|
||||||
id := arg["id"].(string)
|
id := arg["id"].(string)
|
||||||
tpl := arg["tpl"].(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
|
// 导出 PDF 预览时点击块引转换后的脚注跳转不正确 https://github.com/siyuan-note/siyuan/issues/5894
|
||||||
content = strings.ReplaceAll(content, "http://127.0.0.1:"+util.ServerPort+"/#", "#")
|
content = strings.ReplaceAll(content, "http://127.0.0.1:"+util.ServerPort+"/#", "#")
|
||||||
tpl = strings.ReplaceAll(tpl, "{tpl.name}", name)
|
tpl = strings.ReplaceAll(tpl, "{tpl.name}", name)
|
||||||
|
@ -235,7 +235,11 @@ func exportHTML(c *gin.Context) {
|
||||||
id := arg["id"].(string)
|
id := arg["id"].(string)
|
||||||
pdf := arg["pdf"].(bool)
|
pdf := arg["pdf"].(bool)
|
||||||
savePath := arg["savePath"].(string)
|
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{}{
|
ret.Data = map[string]interface{}{
|
||||||
"id": id,
|
"id": id,
|
||||||
"name": name,
|
"name": name,
|
||||||
|
|
|
@ -196,7 +196,7 @@ func exportData(exportFolder string) (err error) {
|
||||||
|
|
||||||
func Preview(id string) string {
|
func Preview(id string) string {
|
||||||
tree, _ := loadTreeByBlockID(id)
|
tree, _ := loadTreeByBlockID(id)
|
||||||
tree = exportTree(tree, false, false)
|
tree = exportTree(tree, false, false, false)
|
||||||
luteEngine := NewLute()
|
luteEngine := NewLute()
|
||||||
luteEngine.SetFootnotes(true)
|
luteEngine.SetFootnotes(true)
|
||||||
md := treenode.FormatNode(tree.Root, luteEngine)
|
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) {
|
func ExportMarkdownHTML(id, savePath string, docx bool) (name, dom string) {
|
||||||
tree, _ := loadTreeByBlockID(id)
|
tree, _ := loadTreeByBlockID(id)
|
||||||
|
|
||||||
tree = exportTree(tree, true, true)
|
tree = exportTree(tree, true, true, false)
|
||||||
name = path.Base(tree.HPath)
|
name = path.Base(tree.HPath)
|
||||||
name = util.FilterFileName(name) // 导出 PDF、HTML 和 Word 时未移除不支持的文件名符号 https://github.com/siyuan-note/siyuan/issues/5614
|
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
|
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)
|
tree, _ := loadTreeByBlockID(id)
|
||||||
var headings []*ast.Node
|
var headings []*ast.Node
|
||||||
if pdf { // 导出 PDF 需要标记目录书签
|
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
|
//if pdf { // TODO: 导出 PDF 时块引转换脚注使用书签跳转 https://github.com/siyuan-note/siyuan/issues/5761
|
||||||
// var footnotesDefs []*ast.Node
|
// var footnotesDefs []*ast.Node
|
||||||
// ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
// 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 {
|
func CopyStdMarkdown(id string) string {
|
||||||
tree, _ := loadTreeByBlockID(id)
|
tree, _ := loadTreeByBlockID(id)
|
||||||
tree = exportTree(tree, false, false)
|
tree = exportTree(tree, false, false, false)
|
||||||
luteEngine := NewLute()
|
luteEngine := NewLute()
|
||||||
luteEngine.SetFootnotes(true)
|
luteEngine.SetFootnotes(true)
|
||||||
luteEngine.SetKramdownIAL(false)
|
luteEngine.SetKramdownIAL(false)
|
||||||
|
@ -967,7 +967,7 @@ func ExportMarkdownContent(id string) (hPath, exportedMd string) {
|
||||||
func exportMarkdownContent(id string) (hPath, exportedMd string) {
|
func exportMarkdownContent(id string) (hPath, exportedMd string) {
|
||||||
tree, _ := loadTreeByBlockID(id)
|
tree, _ := loadTreeByBlockID(id)
|
||||||
hPath = tree.HPath
|
hPath = tree.HPath
|
||||||
tree = exportTree(tree, false, true)
|
tree = exportTree(tree, false, true, false)
|
||||||
luteEngine := NewLute()
|
luteEngine := NewLute()
|
||||||
luteEngine.SetFootnotes(true)
|
luteEngine.SetFootnotes(true)
|
||||||
luteEngine.SetKramdownIAL(false)
|
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()
|
luteEngine := NewLute()
|
||||||
ret = tree
|
ret = tree
|
||||||
id := tree.Root.ID
|
id := tree.Root.ID
|
||||||
|
@ -1244,9 +1244,12 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros bool) (ret *parse.T
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
// 块折叠以后导出 HTML/PDF 固定展开 https://github.com/siyuan-note/siyuan/issues/4064
|
// 支持按照现有折叠状态导出 PDF https://github.com/siyuan-note/siyuan/issues/5941
|
||||||
n.RemoveIALAttr("fold")
|
if !keepFold {
|
||||||
n.RemoveIALAttr("heading-fold")
|
// 块折叠以后导出 HTML/PDF 固定展开 https://github.com/siyuan-note/siyuan/issues/4064
|
||||||
|
n.RemoveIALAttr("fold")
|
||||||
|
n.RemoveIALAttr("heading-fold")
|
||||||
|
}
|
||||||
|
|
||||||
if ast.NodeParagraph == n.Type {
|
if ast.NodeParagraph == n.Type {
|
||||||
if nil == n.FirstChild {
|
if nil == n.FirstChild {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue