diff --git a/public/javascripts/note_editor.js b/public/javascripts/note_editor.js index e949dbf1f..c0b83b76a 100644 --- a/public/javascripts/note_editor.js +++ b/public/javascripts/note_editor.js @@ -4,6 +4,7 @@ const noteEditor = (function() { const noteTitleEl = $("#note-title"); const noteDetailEl = $('#note-detail'); const noteDetailCodeEl = $('#note-detail-code'); + const noteDetailRenderEl = $('#note-detail-render'); const protectButton = $("#protect-button"); const unprotectButton = $("#unprotect-button"); const noteDetailWrapperEl = $("#note-detail-wrapper"); @@ -71,6 +72,9 @@ const noteEditor = (function() { else if (note.detail.type === 'code') { note.detail.note_text = codeEditor.getValue(); } + else if (note.detail.type === 'render') { + // nothing + } else { throwError("Unrecognized type: " + note.detail.type); } @@ -140,10 +144,12 @@ const noteEditor = (function() { noteDetailEl.show(); noteDetailCodeEl.hide(); + noteDetailRenderEl.hide(); } else if (currentNote.detail.type === 'code') { noteDetailEl.hide(); noteDetailCodeEl.show(); + noteDetailRenderEl.hide(); // this needs to happen after the element is shown, otherwise the editor won't be refresheds codeEditor.setValue(currentNote.detail.note_text); @@ -155,6 +161,15 @@ const noteEditor = (function() { CodeMirror.autoLoadMode(codeEditor, info.mode); } } + else if (currentNote.detail.type === 'render') { + noteDetailEl.hide(); + noteDetailCodeEl.hide(); + noteDetailRenderEl.show(); + + const subTree = await server.get('script/subtree/' + getCurrentNoteId()); + + noteDetailRenderEl.html(subTree); + } else { throwError("Unrecognized type " + currentNote.detail.type); } @@ -185,6 +200,9 @@ const noteEditor = (function() { else if (note.detail.type === 'code') { codeEditor.focus(); } + else if (note.detail.type === 'render') { + // do nothing + } else { throwError('Unrecognized type: ' + note.detail.type); } diff --git a/public/javascripts/note_type.js b/public/javascripts/note_type.js index 3cd764cdc..3116c7105 100644 --- a/public/javascripts/note_type.js +++ b/public/javascripts/note_type.js @@ -62,6 +62,9 @@ const noteType = (function() { return found ? found.title : mime; } } + else if (type === 'render') { + return 'Render HTML note'; + } else { throwError('Unrecognized type: ' + type); } @@ -86,6 +89,13 @@ const noteType = (function() { save(); }; + this.selectRender = function() { + self.type('render'); + self.mime(''); + + save(); + }; + this.selectCode = function() { self.type('code'); self.mime(''); diff --git a/routes/api/notes.js b/routes/api/notes.js index 786ac916b..cccdcccd2 100644 --- a/routes/api/notes.js +++ b/routes/api/notes.js @@ -93,10 +93,10 @@ router.put('/:noteId/protect-sub-tree/:isProtected', auth.checkApiAuth, wrap(asy res.send({}); })); -router.put('/:noteId/type/:type/mime/:mime', auth.checkApiAuth, wrap(async (req, res, next) => { - const noteId = req.params.noteId; - const type = req.params.type; - const mime = req.params.mime; +router.put(/\/(.*)\/type\/(.*)\/mime\/(.*)/, auth.checkApiAuth, wrap(async (req, res, next) => { + const noteId = req.params[0]; + const type = req.params[1]; + const mime = req.params[2]; const sourceId = req.headers.source_id; await sql.doInTransaction(async () => { diff --git a/routes/api/script.js b/routes/api/script.js index bca9ad9f9..53cb5ccb3 100644 --- a/routes/api/script.js +++ b/routes/api/script.js @@ -32,7 +32,7 @@ async function getSubTreeScripts(parentId, includedNoteIds, dataKey) { FROM notes JOIN notes_tree USING(note_id) WHERE notes_tree.is_deleted = 0 AND notes.is_deleted = 0 AND notes_tree.parent_note_id = ? AND notes.type = 'code' - AND notes.mime = 'application/javascript'`, [parentId]); + AND (notes.mime = 'application/javascript' OR notes.mime = 'text/html')`, [parentId]); let script = "\r\n"; @@ -54,9 +54,7 @@ async function getSubTreeScripts(parentId, includedNoteIds, dataKey) { child.note_text = data_encryption.decryptString(dataKey, data_encryption.noteTextIv(child.note_id), child.note_text); } - script += '// start of script ' + child.note_title + '\r\n'; script += child.note_text + "\r\n"; - script += '// end of script ' + child.note_title + '\r\n\r\n'; } return script; diff --git a/services/consistency_checks.js b/services/consistency_checks.js index bf4ef4bb1..ea06689b8 100644 --- a/services/consistency_checks.js +++ b/services/consistency_checks.js @@ -214,7 +214,7 @@ async function runAllChecks() { FROM notes WHERE - type != 'text' AND type != 'code'`, + type != 'text' AND type != 'code' AND type != 'render'`, "Note has invalid type", errorList); await runSyncRowChecks("notes", "note_id", errorList); diff --git a/views/index.ejs b/views/index.ejs index 4fa48dbe6..def22fa5b 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -108,6 +108,8 @@