diff --git a/src/sql.py b/src/sql.py index 641f182b6..14e85a019 100644 --- a/src/sql.py +++ b/src/sql.py @@ -17,6 +17,7 @@ def connect(documentPath): conn.row_factory = dict_factory def insert(tablename, rec): + # FIXME: SQL injection! keys = ','.join(rec.keys()) question_marks = ','.join(list('?'*len(rec))) values = tuple(rec.values()) diff --git a/static/js/html2notecase.js b/static/js/html2notecase.js index 0241175cd..4843922e1 100644 --- a/static/js/html2notecase.js +++ b/static/js/html2notecase.js @@ -31,18 +31,11 @@ function html2notecase(contents, note) { let curTag = curContent.substr(0, endOfTag + 1); - //console.log(contents); - for (tagId in tags) { let tag = tags[tagId]; if (contents.substr(index, tag.length) === tag) { found = true; - // if (tagMap.get(index) == undefined) { - // tagMap.get(index) = []; - // } - - // tagMap.get(index).push(key); note.formatting.push({ note_id: note.detail.note_id, @@ -97,31 +90,33 @@ function html2notecase(contents, note) { let match = /^]+?href="([^"]+?)"[^>]+?>([^<]+?)<\/a>/.exec(curContent); if (match !== null) { - note.links.push({ + const targetUrl = match[1]; + const linkText = match[2]; + + const newLink = { note_id: note.detail.note_id, note_offset: index, - target_url: match[1], - lnk_text: match[2] - }); + 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); //console.log("Found link with text: " + match[2] + ", targetting: " + match[1]); - contents = contents.substr(0, index) + match[2] + contents.substr(index + match[0].length); + contents = contents.substr(0, index) + linkText + contents.substr(index + match[0].length); found = true; } - // let imageRegex = /]+src="data:image\/(jpg|png);base64,([^>\"]+)"[^>]+>/; - - // console.log("Testing for image: " + curTag.substr(0, 100)); - // console.log("End of image: " + curTag.substr(curTag.length - 100)); - - // let match = imageRegex.exec(curTag); - - // if (match != null) { - - // } - if (!found) { contents = contents.substr(0, index) + contents.substr(index + endOfTag + 1); } @@ -130,17 +125,26 @@ function html2notecase(contents, note) { let linkMatch = /^(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]/i.exec(curContent); if (linkMatch !== null) { - note.links.push({ + let targetUrl = linkMatch[0]; + + let newLink = { note_id: note.detail.note_id, note_offset: index, - target_url: linkMatch[0], - lnk_text: linkMatch[0] - }); + lnk_text: targetUrl + }; - // console.log(linkMatch[0]); - // console.log(linkMatch[0].length); + const noteIdMatch = /app#([A-Za-z0-9]{22})/.exec(targetUrl); - index += linkMatch[0].length; + if (noteIdMatch !== null) { + newLink.target_note_id = noteIdMatch[1]; + } + else { + newLink.target_url = targetUrl; + } + + note.links.push(newLink); + + index += targetUrl.length; } else { index++; diff --git a/static/js/note.js b/static/js/note.js index a83ae8cc1..b3a642ef0 100644 --- a/static/js/note.js +++ b/static/js/note.js @@ -181,9 +181,9 @@ function addRecentNote(noteTreeId, noteContentId) { // we include the note into recent list only if the user stayed on the note at least 5 seconds if (noteTreeId === globalNote.detail.note_id || noteContentId === globalNote.detail.note_id) { // if it's already there, remove the note - recentNotes = recentNotes.filter(note => note !== noteTreeId); + c = recentNotes.filter(note => note !== noteTreeId); - console.log("added after " + (new Date().getTime() - origDate.getTime())); + //console.log("added after " + (new Date().getTime() - origDate.getTime())); recentNotes.unshift(noteTreeId); } diff --git a/static/js/notecase2html.js b/static/js/notecase2html.js index c4d66f9f7..fcd3c2020 100644 --- a/static/js/notecase2html.js +++ b/static/js/notecase2html.js @@ -26,7 +26,16 @@ function notecase2html(note) { } } else if (el.type === 'link') { - let linkHtml = '' + el.lnk_text + ''; + let targetUrl; + + if (el.target_url) { + targetUrl = el.target_url; + } + else { + targetUrl = "app#" + el.target_note_id; + } + + let linkHtml = '' + el.lnk_text + ''; noteText = noteText.substr(0, el.note_offset + offset) + noteText.substr(el.note_offset + offset + el.lnk_text.length); diff --git a/static/style.css b/static/style.css index bc545af95..9ac84598c 100644 --- a/static/style.css +++ b/static/style.css @@ -33,6 +33,7 @@ ul.fancytree-container { outline: none !important; } +/* icons from https://feathericons.com */ span.fancytree-node > span.fancytree-icon { background-position: 0 0; background-image: url("icons/file.png");