A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
core: allow exports with custom content
ammarahm-ed14d7ec6b4e27
diff --git a/packages/core/models/note.js b/packages/core/models/note.jsindex 904e32768..3148e36d3 100644--- a/packages/core/models/note.js+++ b/packages/core/models/note.js@@ -79,10 +79,12 @@ export default class Note {/**** @param {"html"|"md"|"txt"} format - Format to export into- * @param {string?} rawContent - Use this raw content instead of generating itself+ * @param {string} [contentItem=undefined]+ * @param {boolean} [template=true]+ * @param {string} [rawHTML=undefined] rawHTML - Use this raw content instead of generating itself* @returns {Promise<string | false | undefined>}*/- async export(to = "html", rawContent) {+ async export(to = "html", contentItem, template = true, rawHTML) {if (to !== "txt" && !(await checkIsUserPremium(CHECK_IDS.noteExport)))return false;@@ -94,7 +96,8 @@ export default class Note {createdOn: formatDate(this.data.dateCreated),tags: this.tags.join(", ")};- const contentItem = await this._db.content.raw(this._note.contentId);+ contentItem =+ contentItem || (await this._db.content.raw(this._note.contentId));if (!contentItem) return false;const { data, type } = await this._db.content.downloadMedia(`export-${this.id}`,@@ -105,14 +108,20 @@ export default class Note {switch (to) {case "html":- templateData.content = rawContent || content.toHTML();- return HTMLBuilder.buildHTML(templateData);+ templateData.content = rawHTML || content.toHTML();+ return template+ ? HTMLBuilder.buildHTML(templateData)+ : templateData.content;case "txt":- templateData.content = rawContent || content.toTXT();- return TextBuilder.buildText(templateData);+ templateData.content = rawHTML || content.toTXT();+ return template+ ? TextBuilder.buildText(templateData)+ : templateData.content;case "md":- templateData.content = rawContent || content.toMD();- return MarkdownBuilder.buildMarkdown(templateData);+ templateData.content = rawHTML || content.toMD();+ return template+ ? MarkdownBuilder.buildMarkdown(templateData)+ : templateData.content;default:throw new Error("Export format not supported.");}