From 2f9f9ec36098a9ffdc70339dad2d412f6e52d156 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 11 Dec 2022 10:03:47 +0800 Subject: [PATCH 1/3] =?UTF-8?q?:art:=20=E6=94=AF=E6=8C=81=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E5=AD=90=E6=96=87=E6=A1=A3=E5=AF=BC=E5=87=BA=20Word/P?= =?UTF-8?q?DF=20https://github.com/siyuan-note/siyuan/issues/3219?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/appearance/langs/en_US.json | 1 + app/appearance/langs/es_ES.json | 1 + app/appearance/langs/fr_FR.json | 1 + app/appearance/langs/zh_CHT.json | 1 + app/appearance/langs/zh_CN.json | 1 + app/src/protyle/export/index.ts | 24 ++++++++++++++++++++++-- app/src/util/onGetConfig.ts | 3 ++- kernel/model/export_merge.go | 5 +++++ 8 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index 04a85f105..ceef89e39 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -170,6 +170,7 @@ "exportPDF3": "Page Scale", "exportPDF4": "Remove assets directory", "exportPDF5": "Keep folded", + "exportPDF6": "Fusionar subdocumentos", "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", diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index ebff98a82..2110493af 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -674,6 +674,7 @@ "export3": "Sólo texto de anclaje", "export4": "Notas a pie de página", "export5": "Ref. de anotación en PDF", + "export6": "Fusionar subdocumentos", "export6": "Sobre el manejo del texto ancla en las anotaciones PDF al exportar", "export7": "Nombre de archivo - Número de página - Texto ancla", "export8": "Sólo texto ancla", diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index 0823cde38..7b8e41671 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -170,6 +170,7 @@ "exportPDF3": "Échelle de page", "exportPDF4": "Supprimer le répertoire des actifs", "exportPDF5": "Garder plié", + "exportPDF6": "Fusionner les sous-documents", "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.", diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index 19f4bf0da..38951d1fa 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -170,6 +170,7 @@ "exportPDF3": "頁面縮放", "exportPDF4": "移除 assets 目錄", "exportPDF5": "保持折疊狀態", + "exportPDF6": "合併子文檔", "upload": "上傳", "reminderTip": "提醒時間不能小於當前時間", "wechatTip": "該內容塊將以明文形式發送到雲端,到期時通過微信公眾號模板消息進行推送", diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index 7c78528d5..55773d451 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -170,6 +170,7 @@ "exportPDF3": "页面缩放", "exportPDF4": "移除 assets 目录", "exportPDF5": "保持折叠状态", + "exportPDF6": "合并子文档", "upload": "上传", "reminderTip": "提醒时间不能小于当前时间", "wechatTip": "该内容块将以明文形式发送到云端,到期时通过微信公众号模板消息进行推送", diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts index 5015f8aec..c71145ba7 100644 --- a/app/src/protyle/export/index.ts +++ b/app/src/protyle/export/index.ts @@ -70,6 +70,7 @@ const renderPDF = (id: string) => { pageSize: "A4", removeAssets: true, keepFold: false, + mergeSubdocs: false, })); const servePath = window.location.protocol + "//" + window.location.host; const isDefault = (window.siyuan.config.appearance.mode === 1 && window.siyuan.config.appearance.themeDark === "midnight") || (window.siyuan.config.appearance.mode === 0 && window.siyuan.config.appearance.themeLight === "daylight"); @@ -204,6 +205,13 @@ const renderPDF = (id: string) => { +
@@ -316,6 +324,7 @@ const renderPDF = (id: string) => { fetchPost("/api/export/exportPreviewHTML", { id: "${id}", keepFold: ${localData.keepFold}, + merge: ${localData.mergeSubdocs}, }, response => { if (response.code === 1) { alert(response.msg) @@ -359,10 +368,19 @@ const renderPDF = (id: string) => { const actionElement = document.getElementById('action'); const keepFoldElement = actionElement.querySelector('#keepFold'); keepFoldElement.addEventListener('change', () => { - previewElement.innerHTML = '
' + refreshPreview(); + }); + const mergeSubdocsElement = actionElement.querySelector('#mergeSubdocs'); + mergeSubdocsElement.addEventListener('change', () => { + refreshPreview(); + }); + + const refreshPreview = () => { + previewElement.innerHTML = '
' fetchPost("/api/export/exportPreviewHTML", { id: "${id}", keepFold: keepFoldElement.checked, + merge: mergeSubdocsElement.checked, }, response2 => { if (response2.code === 1) { alert(response2.msg) @@ -371,7 +389,8 @@ const renderPDF = (id: string) => { setPadding(); renderPreview(response2.data.content); }) - }) + }; + actionElement.querySelector("#scale").addEventListener("input", () => { actionElement.querySelector("#scaleTip").innerText = actionElement.querySelector("#scale").value; }) @@ -406,6 +425,7 @@ const renderPDF = (id: string) => { pageSize: actionElement.querySelector("#pageSize").value, }, keepFold: keepFoldElement.checked, + mergeSubdocs: mergeSubdocsElement.checked, removeAssets: actionElement.querySelector("#removeAssets").checked, rootId: "${id}", rootTitle: response.data.name, diff --git a/app/src/util/onGetConfig.ts b/app/src/util/onGetConfig.ts index 599e86eb5..60680fffe 100644 --- a/app/src/util/onGetConfig.ts +++ b/app/src/util/onGetConfig.ts @@ -374,7 +374,8 @@ const initWindow = () => { const msgId = showMessage(window.siyuan.languages.exporting, -1); localStorage.setItem(Constants.LOCAL_EXPORTPDF, JSON.stringify(Object.assign(ipcData.pdfOptions, { removeAssets: ipcData.removeAssets, - keepFold: ipcData.keepFold + keepFold: ipcData.keepFold, + merge: ipcData.mergeSubdocs, }))); try { window.siyuan.printWin.webContents.printToPDF(ipcData.pdfOptions).then((pdfData) => { diff --git a/kernel/model/export_merge.go b/kernel/model/export_merge.go index 140e804ea..2bab6eea1 100644 --- a/kernel/model/export_merge.go +++ b/kernel/model/export_merge.go @@ -79,6 +79,11 @@ func loadTreeNodes(box string, p string, level int) (ret []*ast.Node, err error) heading.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(tree.Root.IALAttr("title"))}) tree.Root.PrependChild(heading) for c := tree.Root.FirstChild; nil != c; c = c.Next { + if ast.NodeParagraph == c.Type && nil == c.FirstChild { + // 剔除空段落 + continue + } + ret = append(ret, c) } return From db131e7f1a84292c7e92ac5aad3189ba5db8f024 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 11 Dec 2022 10:05:57 +0800 Subject: [PATCH 2/3] =?UTF-8?q?:art:=20=E6=94=AF=E6=8C=81=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E5=AD=90=E6=96=87=E6=A1=A3=E5=AF=BC=E5=87=BA=20Word/P?= =?UTF-8?q?DF=20https://github.com/siyuan-note/siyuan/issues/3219?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/util/onGetConfig.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/util/onGetConfig.ts b/app/src/util/onGetConfig.ts index 60680fffe..cac6d6020 100644 --- a/app/src/util/onGetConfig.ts +++ b/app/src/util/onGetConfig.ts @@ -375,7 +375,7 @@ const initWindow = () => { localStorage.setItem(Constants.LOCAL_EXPORTPDF, JSON.stringify(Object.assign(ipcData.pdfOptions, { removeAssets: ipcData.removeAssets, keepFold: ipcData.keepFold, - merge: ipcData.mergeSubdocs, + mergeSubdocs: ipcData.mergeSubdocs, }))); try { window.siyuan.printWin.webContents.printToPDF(ipcData.pdfOptions).then((pdfData) => { From ef35d48a7b118f5e2f9c5d36846cd8b63198bee9 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 11 Dec 2022 10:22:13 +0800 Subject: [PATCH 3/3] =?UTF-8?q?:art:=20=E6=94=AF=E6=8C=81=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E5=AD=90=E6=96=87=E6=A1=A3=E5=AF=BC=E5=87=BA=20Word/P?= =?UTF-8?q?DF=20https://github.com/siyuan-note/siyuan/issues/3219?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/protyle/export/index.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts index c71145ba7..d2969c9e8 100644 --- a/app/src/protyle/export/index.ts +++ b/app/src/protyle/export/index.ts @@ -37,6 +37,13 @@ export const saveExport = (option: { type: string, id: string }) => { +
@@ -50,8 +57,9 @@ export const saveExport = (option: { type: string, id: string }) => { }); btnsElement[1].addEventListener("click", () => { const removeAssets = (wordDialog.element.querySelector("#removeAssets") as HTMLInputElement).checked; - localStorage.setItem(Constants.LOCAL_EXPORTWORD, removeAssets.toString()); - getExportPath(option, removeAssets); + const mergeSubdocs = (wordDialog.element.querySelector("#mergeSubdocs") as HTMLInputElement).checked; + localStorage.setItem(Constants.LOCAL_EXPORTWORD, JSON.stringify({removeAssets, mergeSubdocs})); + getExportPath(option, removeAssets, mergeSubdocs); wordDialog.destroy(); }); } else { @@ -473,7 +481,7 @@ export const destroyPrintWindow = () => { window.siyuan.printWin.destroy(); }; -const getExportPath = (option: { type: string, id: string }, removeAssets?: boolean) => { +const getExportPath = (option: { type: string, id: string }, removeAssets?: boolean, mergeSubdocs?: boolean) => { fetchPost("/api/block/getBlockInfo", { id: option.id }, (response) => { @@ -516,7 +524,8 @@ const getExportPath = (option: { type: string, id: string }, removeAssets?: bool fetchPost(url, { id: option.id, pdf: option.type === "pdf", - removeAssets, + removeAssets: removeAssets, + merge: mergeSubdocs, savePath }, exportResponse => { if (option.type === "word") {