mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 07:01:31 +08:00 
			
		
		
		
	render notes can be edited and can contain HTML markup
This commit is contained in:
		
							parent
							
								
									ab0486aaf1
								
							
						
					
					
						commit
						40a32e6826
					
				
							
								
								
									
										1
									
								
								db/migrations/0095__mime_type_for_render.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								db/migrations/0095__mime_type_for_render.sql
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					UPDATE notes SET mime = 'text/html' WHERE type = 'render';
 | 
				
			||||||
@ -40,7 +40,7 @@ class Note extends Entity {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    isHtml() {
 | 
					    isHtml() {
 | 
				
			||||||
        return (this.type === "code" || this.type === "file") && this.mime === "text/html";
 | 
					        return (this.type === "code" || this.type === "file" || this.type === "render") && this.mime === "text/html";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    getScriptEnv() {
 | 
					    getScriptEnv() {
 | 
				
			||||||
 | 
				
			|||||||
@ -64,7 +64,11 @@ function focus() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function executeCurrentNote() {
 | 
					async function executeCurrentNote() {
 | 
				
			||||||
    if (noteDetailService.getCurrentNoteType() === 'code') {
 | 
					    // ctrl+enter is also used elsewhere so make sure we're running only when appropriate
 | 
				
			||||||
 | 
					    if (noteDetailService.getCurrentNoteType() !== 'code') {
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // make sure note is saved so we load latest changes
 | 
					    // make sure note is saved so we load latest changes
 | 
				
			||||||
    await noteDetailService.saveNoteIfChanged();
 | 
					    await noteDetailService.saveNoteIfChanged();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -82,7 +86,6 @@ async function executeCurrentNote() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    infoService.showMessage("Note executed");
 | 
					    infoService.showMessage("Note executed");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
$(document).bind('keydown', "ctrl+return", executeCurrentNote);
 | 
					$(document).bind('keydown', "ctrl+return", executeCurrentNote);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,12 +1,51 @@
 | 
				
			|||||||
import bundleService from "./bundle.js";
 | 
					import bundleService from "./bundle.js";
 | 
				
			||||||
import server from "./server.js";
 | 
					import server from "./server.js";
 | 
				
			||||||
import noteDetailService from "./note_detail.js";
 | 
					import noteDetailService from "./note_detail.js";
 | 
				
			||||||
 | 
					import noteDetailCodeService from "./note_detail_code.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const $noteDetailCode = $('#note-detail-code');
 | 
				
			||||||
const $noteDetailRender = $('#note-detail-render');
 | 
					const $noteDetailRender = $('#note-detail-render');
 | 
				
			||||||
 | 
					const $toggleEditButton = $('#toggle-edit-button');
 | 
				
			||||||
 | 
					const $renderButton = $('#render-button');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					let codeEditorInitialized;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function show() {
 | 
					async function show() {
 | 
				
			||||||
 | 
					    codeEditorInitialized = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $noteDetailRender.show();
 | 
					    $noteDetailRender.show();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    await render();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$toggleEditButton.click(() => {
 | 
				
			||||||
 | 
					    if ($noteDetailCode.is(":visible")) {
 | 
				
			||||||
 | 
					        $noteDetailCode.hide();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else {
 | 
				
			||||||
 | 
					        if (!codeEditorInitialized) {
 | 
				
			||||||
 | 
					            noteDetailCodeService.show();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            codeEditorInitialized = true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else {
 | 
				
			||||||
 | 
					            $noteDetailCode.show();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$renderButton.click(render);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async function render() {
 | 
				
			||||||
 | 
					    // ctrl+enter is also used elsewhere so make sure we're running only when appropriate
 | 
				
			||||||
 | 
					    if (noteDetailService.getCurrentNoteType() !== 'render') {
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (codeEditorInitialized) {
 | 
				
			||||||
 | 
					        await noteDetailService.saveNoteIfChanged();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const bundle = await server.get('script/bundle/' + noteDetailService.getCurrentNoteId());
 | 
					    const bundle = await server.get('script/bundle/' + noteDetailService.getCurrentNoteId());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $noteDetailRender.html(bundle.html);
 | 
					    $noteDetailRender.html(bundle.html);
 | 
				
			||||||
@ -14,8 +53,10 @@ async function show() {
 | 
				
			|||||||
    await bundleService.executeBundle(bundle);
 | 
					    await bundleService.executeBundle(bundle);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$(document).bind('keydown', "ctrl+return", render);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
    show,
 | 
					    show,
 | 
				
			||||||
    getContent: () => null,
 | 
					    getContent: noteDetailCodeService.getContent,
 | 
				
			||||||
    focus: () => null
 | 
					    focus: () => null
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -4,6 +4,9 @@ import server from './server.js';
 | 
				
			|||||||
import infoService from "./info.js";
 | 
					import infoService from "./info.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const $executeScriptButton = $("#execute-script-button");
 | 
					const $executeScriptButton = $("#execute-script-button");
 | 
				
			||||||
 | 
					const $toggleEditButton = $('#toggle-edit-button');
 | 
				
			||||||
 | 
					const $renderButton = $('#render-button');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const noteTypeModel = new NoteTypeModel();
 | 
					const noteTypeModel = new NoteTypeModel();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function NoteTypeModel() {
 | 
					function NoteTypeModel() {
 | 
				
			||||||
@ -107,7 +110,7 @@ function NoteTypeModel() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    this.selectRender = function() {
 | 
					    this.selectRender = function() {
 | 
				
			||||||
        self.type('render');
 | 
					        self.type('render');
 | 
				
			||||||
        self.mime('');
 | 
					        self.mime('text/html');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        save();
 | 
					        save();
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
@ -128,6 +131,9 @@ function NoteTypeModel() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    this.updateExecuteScriptButtonVisibility = function() {
 | 
					    this.updateExecuteScriptButtonVisibility = function() {
 | 
				
			||||||
        $executeScriptButton.toggle(self.mime().startsWith('application/javascript'));
 | 
					        $executeScriptButton.toggle(self.mime().startsWith('application/javascript'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $toggleEditButton.toggle(self.type() === 'render');
 | 
				
			||||||
 | 
					        $renderButton.toggle(self.type() === 'render');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -279,6 +279,10 @@ div.ui-tooltip {
 | 
				
			|||||||
    min-height: 200px;
 | 
					    min-height: 200px;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#note-detail-render {
 | 
				
			||||||
 | 
					    min-height: 200px;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.CodeMirror {
 | 
					.CodeMirror {
 | 
				
			||||||
    font-family: "Liberation Mono", "Lucida Console", monospace;
 | 
					    font-family: "Liberation Mono", "Lucida Console", monospace;
 | 
				
			||||||
    height: auto;
 | 
					    height: auto;
 | 
				
			||||||
 | 
				
			|||||||
@ -3,7 +3,7 @@
 | 
				
			|||||||
const build = require('./build');
 | 
					const build = require('./build');
 | 
				
			||||||
const packageJson = require('../../package');
 | 
					const packageJson = require('../../package');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const APP_DB_VERSION = 94;
 | 
					const APP_DB_VERSION = 95;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = {
 | 
					module.exports = {
 | 
				
			||||||
    appVersion: packageJson.version,
 | 
					    appVersion: packageJson.version,
 | 
				
			||||||
 | 
				
			|||||||
@ -73,7 +73,7 @@ function getParams(params) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getScriptBundle(note, root = true, scriptEnv = null, includedNoteIds = []) {
 | 
					async function getScriptBundle(note, root = true, scriptEnv = null, includedNoteIds = []) {
 | 
				
			||||||
    if (!note.isJavaScript() && !note.isHtml() && note.type !== 'render') {
 | 
					    if (!note.isJavaScript() && !note.isHtml()) {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -95,6 +95,14 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
          <span id="note-id-display" title="Note ID"></span>
 | 
					          <span id="note-id-display" title="Note ID"></span>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          <button class="btn btn-sm"
 | 
				
			||||||
 | 
					                  style="display: none; margin-right: 10px"
 | 
				
			||||||
 | 
					                  id="toggle-edit-button">Toggle edit</button>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          <button class="btn btn-sm"
 | 
				
			||||||
 | 
					                  style="display: none; margin-right: 10px"
 | 
				
			||||||
 | 
					                  id="render-button">Render <kbd>Ctrl+Enter</kbd></button>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          <button class="btn btn-sm"
 | 
					          <button class="btn btn-sm"
 | 
				
			||||||
                  style="display: none; margin-right: 10px"
 | 
					                  style="display: none; margin-right: 10px"
 | 
				
			||||||
                  id="execute-script-button">Execute <kbd>Ctrl+Enter</kbd></button>
 | 
					                  id="execute-script-button">Execute <kbd>Ctrl+Enter</kbd></button>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user