mirror of
https://github.com/zadam/trilium.git
synced 2025-03-09 05:25:47 +08:00
added show note source
This commit is contained in:
parent
5acf84aece
commit
7aff20bb0d
2 changed files with 61 additions and 0 deletions
56
public/javascripts/dialogs/note_source.js
Normal file
56
public/javascripts/dialogs/note_source.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
"use strict";
|
||||
|
||||
const noteSource = (function() {
|
||||
const dialogEl = $("#note-source-dialog");
|
||||
const noteSourceEl = $("#note-source");
|
||||
|
||||
function showDialog() {
|
||||
glob.activeDialog = dialogEl;
|
||||
|
||||
dialogEl.dialog({
|
||||
modal: true,
|
||||
width: 800
|
||||
});
|
||||
|
||||
const noteText = noteEditor.getCurrentNote().detail.note_text;
|
||||
|
||||
noteSourceEl.text(formatHtml(noteText));
|
||||
}
|
||||
|
||||
function formatHtml(str) {
|
||||
const div = document.createElement('div');
|
||||
div.innerHTML = str.trim();
|
||||
|
||||
return formatNode(div, 0).innerHTML.trim();
|
||||
}
|
||||
|
||||
function formatNode(node, level) {
|
||||
const indentBefore = new Array(level++ + 1).join(' ');
|
||||
const indentAfter = new Array(level - 1).join(' ');
|
||||
let textNode;
|
||||
|
||||
for (let i = 0; i < node.children.length; i++) {
|
||||
textNode = document.createTextNode('\n' + indentBefore);
|
||||
node.insertBefore(textNode, node.children[i]);
|
||||
|
||||
formatNode(node.children[i], level);
|
||||
|
||||
if (node.lastElementChild === node.children[i]) {
|
||||
textNode = document.createTextNode('\n' + indentAfter);
|
||||
node.appendChild(textNode);
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
$(document).bind('keydown', 'ctrl+u', e => {
|
||||
showDialog();
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
return {
|
||||
showDialog
|
||||
};
|
||||
})();
|
|
@ -326,6 +326,10 @@
|
|||
</table>
|
||||
</div>
|
||||
|
||||
<div id="note-source-dialog" title="Note source" style="display: none; padding: 20px;">
|
||||
<pre id="note-source"></pre>
|
||||
</div>
|
||||
|
||||
<div id="tooltip" style="display: none;"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
@ -390,6 +394,7 @@
|
|||
<script src="javascripts/dialogs/event_log.js"></script>
|
||||
<script src="javascripts/dialogs/edit_tree_prefix.js"></script>
|
||||
<script src="javascripts/dialogs/sql_console.js"></script>
|
||||
<script src="javascripts/dialogs/note_source.js"></script>
|
||||
|
||||
<script src="javascripts/link.js"></script>
|
||||
<script src="javascripts/sync.js"></script>
|
||||
|
|
Loading…
Reference in a new issue