mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
cleanup
This commit is contained in:
parent
0b5aeee0ce
commit
e862ddae13
@ -48,7 +48,7 @@
|
||||
<div style="clear: both; height: 0"></div>
|
||||
|
||||
<div id="noteDetail" style="overflow: scroll; height: 100%;">
|
||||
<p>This prototype version supports basic editing, including some formatting (bold, italic, strike-through, underscore), images (just paste it into editor) and links. To edit the note, just click on title or content and you can directly modify it. Changes are saved immediatelly.</p>
|
||||
<p>This prototype version supports basic editing, including some formatting (bold, italic, strike-through, underscore), images (just paste it into editor) and links. To edit the note, just click on title or content and you can directly modify it. Changes are saved immediately.</p>
|
||||
|
||||
<p>You can work with the tree using following keyboard shortcuts:</p>
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
function html2notecase(contents, note) {
|
||||
//console.log("'" + contents + "'");
|
||||
|
||||
// remove any possible extra newlines which might be inserted - all relevant new lines should be only in <br> and <p>
|
||||
contents = contents.replace(/(?:\r\n|\r|\n)/, '');
|
||||
|
||||
@ -23,16 +21,16 @@ function html2notecase(contents, note) {
|
||||
|
||||
if (contents[index] === '<') {
|
||||
let found = false;
|
||||
let endOfTag = curContent.indexOf('>');
|
||||
const endOfTag = curContent.indexOf('>');
|
||||
|
||||
if (endOfTag === -1) {
|
||||
console.log("Can't find the end of the tag");
|
||||
}
|
||||
|
||||
let curTag = curContent.substr(0, endOfTag + 1);
|
||||
const curTag = curContent.substr(0, endOfTag + 1);
|
||||
|
||||
for (tagId in tags) {
|
||||
let tag = tags[tagId];
|
||||
const tag = tags[tagId];
|
||||
|
||||
if (contents.substr(index, tag.length) === tag) {
|
||||
found = true;
|
||||
@ -67,9 +65,7 @@ function html2notecase(contents, note) {
|
||||
let endOfDataPos = dataStart.indexOf('"');
|
||||
|
||||
if (endOfDataPos !== -1) {
|
||||
//console.log("Found the end of image data");
|
||||
|
||||
let imageData = dataStart.substr(0, endOfDataPos);
|
||||
const imageData = dataStart.substr(0, endOfDataPos);
|
||||
|
||||
note.images.push({
|
||||
note_id: note.detail.note_id,
|
||||
@ -80,18 +76,16 @@ function html2notecase(contents, note) {
|
||||
|
||||
contents = contents.substr(0, index) + contents.substr(index + curTag.length);
|
||||
|
||||
//console.log("Parsed image: " + imageData.substr(0, 100));
|
||||
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let match = /^<a[^>]+?href="([^"]+?)"[^>]+?>([^<]+?)<\/a>/.exec(curContent);
|
||||
const linkMatch = /^<a[^>]+?href="([^"]+?)"[^>]+?>([^<]+?)<\/a>/.exec(curContent);
|
||||
|
||||
if (match !== null) {
|
||||
const targetUrl = match[1];
|
||||
const linkText = match[2];
|
||||
if (linkMatch !== null) {
|
||||
const targetUrl = linkMatch[1];
|
||||
const linkText = linkMatch[2];
|
||||
|
||||
const newLink = {
|
||||
note_id: note.detail.note_id,
|
||||
@ -109,10 +103,8 @@ function html2notecase(contents, note) {
|
||||
}
|
||||
|
||||
note.links.push(newLink);
|
||||
|
||||
//console.log("Found link with text: " + match[2] + ", targetting: " + match[1]);
|
||||
|
||||
contents = contents.substr(0, index) + linkText + contents.substr(index + match[0].length);
|
||||
contents = contents.substr(0, index) + linkText + contents.substr(index + linkMatch[0].length);
|
||||
|
||||
found = true;
|
||||
}
|
||||
@ -125,9 +117,9 @@ function html2notecase(contents, note) {
|
||||
let linkMatch = /^(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]/i.exec(curContent);
|
||||
|
||||
if (linkMatch !== null) {
|
||||
let targetUrl = linkMatch[0];
|
||||
const targetUrl = linkMatch[0];
|
||||
|
||||
let newLink = {
|
||||
const newLink = {
|
||||
note_id: note.detail.note_id,
|
||||
note_offset: index,
|
||||
lnk_text: targetUrl
|
||||
@ -154,7 +146,5 @@ function html2notecase(contents, note) {
|
||||
|
||||
contents = contents.trim();
|
||||
|
||||
//console.log('"' + contents + '"');
|
||||
|
||||
note.detail.note_text = contents;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
let tags = {
|
||||
const tags = {
|
||||
1: "<b>",
|
||||
2: "</b>",
|
||||
3: "<i>",
|
||||
@ -85,19 +85,6 @@ $(document).ready(function() {
|
||||
|
||||
var globalNote;
|
||||
|
||||
function setParent(noteId, newParentKey, successCallback) {
|
||||
let newNoteName = "new note";
|
||||
|
||||
$.ajax({
|
||||
url: baseUrl + 'notes/' + nodeId + '/setParent/' + newParentKey,
|
||||
type: 'PUT',
|
||||
contentType: "application/json",
|
||||
success: function(result) {
|
||||
successCallback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function createNewTopLevelNote() {
|
||||
let rootNode = $("#tree").fancytree("getRootNode");
|
||||
|
||||
|
@ -5,13 +5,12 @@ function notecase2html(note) {
|
||||
note.links.forEach(el => el.type = 'link');
|
||||
note.images.forEach(el => el.type = 'image');
|
||||
|
||||
let all = note.formatting.concat(note.links).concat(note.images);
|
||||
all.sort(function compare(a, b) {
|
||||
const allTags = note.formatting.concat(note.links).concat(note.images);
|
||||
allTags.sort(function compare(a, b) {
|
||||
return a.note_offset - b.note_offset;
|
||||
});
|
||||
|
||||
let offset = 0;
|
||||
let lastTag = null;
|
||||
|
||||
function inject(target, injected, position) {
|
||||
offset += injected.length;
|
||||
@ -19,7 +18,7 @@ function notecase2html(note) {
|
||||
return noteText.substr(0, position) + injected + noteText.substr(position);
|
||||
}
|
||||
|
||||
for (let el of all) {
|
||||
for (const el of allTags) {
|
||||
if (el.type === 'formatting') {
|
||||
if (tags[el.fmt_tag]) {
|
||||
noteText = inject(noteText, tags[el.fmt_tag], el.note_offset + offset);
|
||||
@ -35,7 +34,7 @@ function notecase2html(note) {
|
||||
targetUrl = "app#" + el.target_note_id;
|
||||
}
|
||||
|
||||
let linkHtml = '<a href="' + targetUrl + '">' + el.lnk_text + '</a>';
|
||||
const linkHtml = '<a href="' + targetUrl + '">' + el.lnk_text + '</a>';
|
||||
|
||||
noteText = noteText.substr(0, el.note_offset + offset) + noteText.substr(el.note_offset + offset + el.lnk_text.length);
|
||||
|
||||
@ -44,9 +43,9 @@ function notecase2html(note) {
|
||||
offset -= el.lnk_text.length;
|
||||
}
|
||||
else if (el.type === 'image') {
|
||||
let type = el.is_png ? "png" : "jpg";
|
||||
const type = el.is_png ? "png" : "jpg";
|
||||
|
||||
let imgHtml = '<img alt="Embedded Image" src="data:image/' + type + ';base64,' + el.image_data + '" />';
|
||||
const imgHtml = '<img alt="Embedded Image" src="data:image/' + type + ';base64,' + el.image_data + '" />';
|
||||
|
||||
noteText = inject(noteText, imgHtml, el.note_offset + offset);
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ $(function(){
|
||||
}
|
||||
|
||||
function copyTitle(notes) {
|
||||
for (let note of notes) {
|
||||
for (const note of notes) {
|
||||
globalNoteNames[note.note_id] = note.note_title;
|
||||
|
||||
note.title = note.note_title;
|
||||
@ -185,7 +185,7 @@ $(function(){
|
||||
});
|
||||
|
||||
$("input[name=search]").keyup(function (e) {
|
||||
let match = $(this).val();
|
||||
const match = $(this).val();
|
||||
|
||||
if (e && e.which === $.ui.keyCode.ESCAPE || $.trim(match) === "") {
|
||||
$("button#btnResetSearch").click();
|
||||
@ -193,14 +193,14 @@ $("input[name=search]").keyup(function (e) {
|
||||
}
|
||||
|
||||
// Pass a string to perform case insensitive matching
|
||||
let tree = $("#tree").fancytree("getTree");
|
||||
const tree = $("#tree").fancytree("getTree");
|
||||
tree.filterBranches(match);
|
||||
}).focus();
|
||||
|
||||
$("button#btnResetSearch").click(function () {
|
||||
$("input[name=search]").val("");
|
||||
|
||||
let tree = $("#tree").fancytree("getTree");
|
||||
const tree = $("#tree").fancytree("getTree");
|
||||
tree.clearFilter();
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user