- contents = contents.replace(/(?:\r\n|\r|\n)/, '');
-
- // some editors insert this font stuff which messes up parsing by doubling newlines
- contents = contents.replace(/]*>/g, '');
- contents = contents.replace(/<\/font>/g, '');
- contents = contents.replace(/ /g, '');
- contents = contents.replace(/ /g, ' ');
-
- let index = 0;
-
- while (index < contents.length) {
- let curContent = contents.substr(index);
-
- if (contents[index] === '<') {
- let found = false;
- const endOfTag = curContent.indexOf('>');
-
- if (endOfTag === -1) {
- console.log("Can't find the end of the tag");
- }
-
- const curTag = curContent.substr(0, endOfTag + 1);
-
- for (tagId in tags) {
- const tag = tags[tagId];
-
- if (contents.substr(index, tag.length) === tag) {
- found = true;
-
- note.formatting.push({
- note_id: note.detail.note_id,
- note_offset: index,
- fmt_tag: tagId,
- fmt_color: '',
- fmt_font: '',
- fmt_value: 100
- });
-
- contents = contents.substr(0, index) + contents.substr(index + tag.length);
-
- break;
- }
- }
-
- if (curTag.substr(0, 4) === " $1
<\/p>/g, '\n');
- contents = contents.replace(/
<\/p>/g, '\n');
- contents = contents.replace(/
/g, '\n');
- contents = contents.replace(/
/g, '\n');
- contents = contents.replace(/<\/p>/g, '\n');
- contents = contents.replace(/]+?href="([^"]+?)"[^>]*?>([^<]+?)<\/a>/.exec(curContent);
-
- if (linkMatch !== null) {
- const targetUrl = linkMatch[1];
- const linkText = linkMatch[2];
-
- const newLink = {
- note_id: note.detail.note_id,
- note_offset: index,
- lnk_text: linkText
- };
-
- const noteIdMatch = /app#([A-Za-z0-9]{22})/.exec(targetUrl);
-
- if (noteIdMatch !== null) {
- newLink.target_note_id = noteIdMatch[1];
- }
- else {
- newLink.target_url = targetUrl;
- }
-
- note.links.push(newLink);
-
- contents = contents.substr(0, index) + linkText + contents.substr(index + linkMatch[0].length);
-
- // we'll skip the link text so that it's not processed twice (second time by link auto detection)
- index += linkText.length;
-
- found = true;
- }
-
- if (!found) {
- contents = contents.substr(0, index) + contents.substr(index + endOfTag + 1);
- }
- }
- else {
- let linkMatch = /^(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]/i.exec(curContent);
-
- if (linkMatch !== null) {
- const targetUrl = linkMatch[0];
-
- const newLink = {
- note_id: note.detail.note_id,
- note_offset: index,
- lnk_text: targetUrl
- };
-
- const noteIdMatch = /app#([A-Za-z0-9]{22})/.exec(targetUrl);
-
- if (noteIdMatch !== null) {
- newLink.target_note_id = noteIdMatch[1];
- }
- else {
- newLink.target_url = targetUrl;
- }
-
- note.links.push(newLink);
-
- index += targetUrl.length;
- }
- else {
- index++;
- }
- }
- }
-
- contents = contents.trim();
-
- note.detail.note_text = contents;
-}
\ No newline at end of file
diff --git a/static/js/note.js b/static/js/note.js
index e641a97b7..d694efbc9 100644
--- a/static/js/note.js
+++ b/static/js/note.js
@@ -58,6 +58,28 @@ $(document).ready(function() {
$(".note-editable").attr("tabindex", 2);
});
+function html2notecase(contents, note) {
+ note.formatting = [];
+ note.links = [];
+ note.images = [];
+
+ note.detail.note_text = contents;
+
+ if (!note.detail.encryption) {
+ const linkRegexp = /]+?href="[^"]*kapp#([A-Za-z0-9]{22})"[^>]*?>[^<]+?<\/a>/g;
+ let match;
+
+ while (match = linkRegexp.exec(contents)) {
+ console.log("adding link for " + match[1]);
+
+ note.links.push({
+ note_id: note.detail.note_id,
+ target_note_id: match[1]
+ });
+ }
+ }
+}
+
function updateNoteFromInputs(note) {
let contents = $('#noteDetail').summernote('code');
@@ -194,14 +216,12 @@ function loadNote(noteId) {
$("#noteTitle").val(note.detail.note_title);
- let noteText = notecase2html(note);
-
noteChangeDisabled = true;
// Clear contents and remove all stored history. This is to prevent undo from going across notes
$('#noteDetail').summernote('reset');
- $('#noteDetail').summernote('code', noteText);
+ $('#noteDetail').summernote('code', note.detail.note_text);
document.location.hash = noteId;
diff --git a/static/js/notecase2html.js b/static/js/notecase2html.js
deleted file mode 100644
index 335034daf..000000000
--- a/static/js/notecase2html.js
+++ /dev/null
@@ -1,67 +0,0 @@
-function notecase2html(note) {
- if (globalHtmlEnabled) {
- return note.detail.note_text;
- }
-
- let noteText = note.detail.note_text;
-
- note.formatting.forEach(el => el.type = 'formatting');
- note.links.forEach(el => el.type = 'link');
- note.images.forEach(el => el.type = 'image');
-
- 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;
-
- function inject(target, injected, position) {
- offset += injected.length;
-
- return noteText.substr(0, position) + injected + noteText.substr(position);
- }
-
- 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);
- }
- }
- else if (el.type === 'link') {
- let targetUrl;
-
- if (el.target_url) {
- targetUrl = el.target_url;
- }
- else {
- targetUrl = "app#" + el.target_note_id;
- }
-
- const linkHtml = '' + el.lnk_text + '';
-
- noteText = noteText.substr(0, el.note_offset + offset) + noteText.substr(el.note_offset + offset + el.lnk_text.length);
-
- noteText = inject(noteText, linkHtml, el.note_offset + offset);
-
- offset -= el.lnk_text.length;
- }
- else if (el.type === 'image') {
- const type = el.is_png ? "png" : "jpg";
-
- const imgHtml = '
';
-
- noteText = inject(noteText, imgHtml, el.note_offset + offset);
- }
- }
-
- noteText = noteText.replace(/(?:\r\n|\r)/g, '\n');
-
- noteText = noteText.replace(/(.+)\n/g, '