mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-07 16:42:27 +08:00

# Conflicts: # src/public/javascripts/dialogs/add_link.js # src/public/javascripts/dialogs/export.js # src/public/javascripts/dialogs/import.js # src/public/javascripts/dialogs/note_info.js # src/public/javascripts/services/search_notes.js
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
import appContext from "../services/app_context.js";
|
|
import utils from "../services/utils.js";
|
|
|
|
const $dialog = $("#note-source-dialog");
|
|
const $noteSource = $("#note-source");
|
|
|
|
export function showDialog() {
|
|
utils.openDialog($dialog);
|
|
|
|
const noteText = appContext.tabManager.getActiveTabNote().content;
|
|
|
|
$noteSource.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;
|
|
} |