yet another refactoring of working with note's payload/content

This commit is contained in:
zadam
2019-03-26 22:24:04 +01:00
parent 4bdcf32475
commit 29c60581a6
31 changed files with 126 additions and 239 deletions

View File

@@ -18,32 +18,32 @@ async function exportSingleNote(exportContext, branch, format, res) {
let payload, extension, mime;
const noteContent = await note.getNoteContent();
let content = await note.getContent();
if (note.type === 'text') {
if (format === 'html') {
if (!noteContent.content.toLowerCase().includes("<html")) {
noteContent.content = '<html><head><meta charset="utf-8"></head><body>' + noteContent.content + '</body></html>';
if (!content.toLowerCase().includes("<html")) {
content = '<html><head><meta charset="utf-8"></head><body>' + content + '</body></html>';
}
payload = html.prettyPrint(noteContent.content, {indent_size: 2});
payload = html.prettyPrint(content, {indent_size: 2});
extension = 'html';
mime = 'text/html';
}
else if (format === 'markdown') {
const turndownService = new TurndownService();
payload = turndownService.turndown(noteContent.content);
payload = turndownService.turndown(content);
extension = 'md';
mime = 'text/x-markdown'
}
}
else if (note.type === 'code') {
payload = noteContent.content;
payload = content;
extension = mimeTypes.extension(note.mime) || 'code';
mime = note.mime;
}
else if (note.type === 'relation-map' || note.type === 'search') {
payload = noteContent.content;
payload = content;
extension = 'json';
mime = 'application/json';
}