feat: make note.export accept raw content

This commit is contained in:
thecodrr
2021-02-20 12:32:41 +05:00
parent cc8267820e
commit e92bea200a

View File

@@ -50,8 +50,9 @@ export default class Note {
/** /**
* *
* @param {"html"|"md"|"txt"} format - Format to export into * @param {"html"|"md"|"txt"} format - Format to export into
* @param {string?} rawContent - Use this raw content instead of generating itself
*/ */
async export(to = "html") { async export(to = "html", rawContent) {
const templateData = { const templateData = {
metadata: this.data, metadata: this.data,
title: this.title, title: this.title,
@@ -66,13 +67,13 @@ export default class Note {
switch (to) { switch (to) {
case "html": case "html":
templateData.content = content.toHTML(); templateData.content = rawContent || content.toHTML();
return HTMLBuilder.buildHTML(templateData); return HTMLBuilder.buildHTML(templateData);
case "txt": case "txt":
templateData.content = content.toTXT(); templateData.content = rawContent || content.toTXT();
return TextBuilder.buildText(templateData); return TextBuilder.buildText(templateData);
case "md": case "md":
templateData.content = content.toMD(); templateData.content = rawContent || content.toMD();
return MarkdownBuilder.buildMarkdown(templateData); return MarkdownBuilder.buildMarkdown(templateData);
default: default:
throw new Error("Export format not supported."); throw new Error("Export format not supported.");