From bb8fd2b054e09190e6642231f70e85e554808e02 Mon Sep 17 00:00:00 2001 From: contributor Date: Wed, 3 May 2023 16:19:28 +0300 Subject: [PATCH 1/3] zip export - set note title as document.title --- src/services/export/zip.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/services/export/zip.js b/src/services/export/zip.js index c58afca9f..6bbd1b6ed 100644 --- a/src/services/export/zip.js +++ b/src/services/export/zip.js @@ -248,6 +248,7 @@ async function exportToZip(taskContext, branch, format, res, setHeaders = true) if (noteMeta.format === 'html') { if (!content.substr(0, 100).toLowerCase().includes(" element will make sure external links are openable - https://github.com/zadam/trilium/issues/1289#issuecomment-704066809 content = ` @@ -256,10 +257,11 @@ async function exportToZip(taskContext, branch, format, res, setHeaders = true) + ${htmlTitle}
-

${utils.escapeHtml(title)}

+

${htmlTitle}

${content}
From 386e8dd32eb08f767bba02fe8da61d1753068a03 Mon Sep 17 00:00:00 2001 From: contributor Date: Thu, 4 May 2023 19:56:02 +0300 Subject: [PATCH 2/3] zip import - remove html tags added by Trilium --- src/services/export/zip.js | 4 ++-- src/services/import/zip.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/services/export/zip.js b/src/services/export/zip.js index 6bbd1b6ed..d31927d19 100644 --- a/src/services/export/zip.js +++ b/src/services/export/zip.js @@ -257,11 +257,11 @@ async function exportToZip(taskContext, branch, format, res, setHeaders = true) - ${htmlTitle} + ${htmlTitle}
-

${htmlTitle}

+

${htmlTitle}

${content}
diff --git a/src/services/import/zip.js b/src/services/import/zip.js index abe3b58a9..74a942113 100644 --- a/src/services/import/zip.js +++ b/src/services/import/zip.js @@ -240,6 +240,8 @@ async function importZip(taskContext, fileBuffer, importRootNote) { return /^(?:[a-z]+:)?\/\//i.test(url); } + content = removeTrilumTags(content); + content = content.replace(/

([^<]*)<\/h1>/gi, (match, text) => { if (noteTitle.trim() === text.trim()) { return ""; // remove whole H1 tag @@ -325,6 +327,18 @@ async function importZip(taskContext, fileBuffer, importRootNote) { return content; } + function removeTrilumTags(content) { + const tagsToRemove = [ + '

([^<]*)<\/h1>', + '([^<]*)<\/title>' + ] + for (const tag of tagsToRemove) { + let re = new RegExp(tag, "gi"); + content = content.replace(re, ''); + } + return content; + } + function processNoteContent(noteMeta, type, mime, content, noteTitle, filePath) { if (noteMeta?.format === 'markdown' || (!noteMeta && taskContext.data.textImportedAsText && ['text/markdown', 'text/x-markdown'].includes(mime))) { From bb9631476e5d22db78a5d8390aece8670c7ea415 Mon Sep 17 00:00:00 2001 From: contributor <foss.contributor@gmail.com> Date: Wed, 3 May 2023 18:49:46 +0300 Subject: [PATCH 3/3] bump metaFile format version --- src/services/export/zip.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/export/zip.js b/src/services/export/zip.js index d31927d19..1bc73f768 100644 --- a/src/services/export/zip.js +++ b/src/services/export/zip.js @@ -417,7 +417,7 @@ ${markdownContent}`; const rootMeta = getNoteMeta(branch, { notePath: [] }, existingFileNames); const metaFile = { - formatVersion: 1, + formatVersion: 2, appVersion: packageInfo.version, files: [ rootMeta ] };