mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	basic support for internal links
This commit is contained in:
		| @@ -17,6 +17,7 @@ def connect(documentPath): | |||||||
|     conn.row_factory = dict_factory |     conn.row_factory = dict_factory | ||||||
|  |  | ||||||
| def insert(tablename, rec): | def insert(tablename, rec): | ||||||
|  |     # FIXME: SQL injection! | ||||||
|     keys = ','.join(rec.keys()) |     keys = ','.join(rec.keys()) | ||||||
|     question_marks = ','.join(list('?'*len(rec))) |     question_marks = ','.join(list('?'*len(rec))) | ||||||
|     values = tuple(rec.values()) |     values = tuple(rec.values()) | ||||||
|   | |||||||
| @@ -31,18 +31,11 @@ function html2notecase(contents, note) { | |||||||
|  |  | ||||||
|             let curTag = curContent.substr(0, endOfTag + 1); |             let curTag = curContent.substr(0, endOfTag + 1); | ||||||
|  |  | ||||||
|             //console.log(contents); |  | ||||||
|  |  | ||||||
|             for (tagId in tags) { |             for (tagId in tags) { | ||||||
|                 let tag = tags[tagId]; |                 let tag = tags[tagId]; | ||||||
|  |  | ||||||
|                 if (contents.substr(index, tag.length) === tag) { |                 if (contents.substr(index, tag.length) === tag) { | ||||||
|                     found = true; |                     found = true; | ||||||
|                     // if (tagMap.get(index) == undefined) { |  | ||||||
|                     //   tagMap.get(index) = []; |  | ||||||
|                     // } |  | ||||||
|  |  | ||||||
|                     // tagMap.get(index).push(key); |  | ||||||
|  |  | ||||||
|                     note.formatting.push({ |                     note.formatting.push({ | ||||||
|                         note_id: note.detail.note_id, |                         note_id: note.detail.note_id, | ||||||
| @@ -97,31 +90,33 @@ function html2notecase(contents, note) { | |||||||
|             let match = /^<a[^>]+?href="([^"]+?)"[^>]+?>([^<]+?)<\/a>/.exec(curContent); |             let match = /^<a[^>]+?href="([^"]+?)"[^>]+?>([^<]+?)<\/a>/.exec(curContent); | ||||||
|  |  | ||||||
|             if (match !== null) { |             if (match !== null) { | ||||||
|                 note.links.push({ |                 const targetUrl = match[1]; | ||||||
|  |                 const linkText = match[2]; | ||||||
|  |  | ||||||
|  |                 const newLink = { | ||||||
|                     note_id: note.detail.note_id, |                     note_id: note.detail.note_id, | ||||||
|                     note_offset: index, |                     note_offset: index, | ||||||
|                     target_url: match[1], |                     lnk_text: linkText | ||||||
|                     lnk_text: match[2] |                 }; | ||||||
|                 }); |  | ||||||
|  |                 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]); |                 //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; |                 found = true; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             // let imageRegex = /<img[^>]+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) { |             if (!found) { | ||||||
|                 contents = contents.substr(0, index) + contents.substr(index + endOfTag + 1); |                 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); |             let linkMatch = /^(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]/i.exec(curContent); | ||||||
|  |  | ||||||
|             if (linkMatch !== null) { |             if (linkMatch !== null) { | ||||||
|                 note.links.push({ |                 let targetUrl = linkMatch[0]; | ||||||
|  |  | ||||||
|  |                 let newLink = { | ||||||
|                     note_id: note.detail.note_id, |                     note_id: note.detail.note_id, | ||||||
|                     note_offset: index, |                     note_offset: index, | ||||||
|                     target_url: linkMatch[0], |                     lnk_text: targetUrl | ||||||
|                     lnk_text: linkMatch[0] |                 }; | ||||||
|                 }); |  | ||||||
|  |  | ||||||
|                 // console.log(linkMatch[0]); |                 const noteIdMatch = /app#([A-Za-z0-9]{22})/.exec(targetUrl); | ||||||
|                 // console.log(linkMatch[0].length); |  | ||||||
|  |  | ||||||
|                 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 { |             else { | ||||||
|                 index++; |                 index++; | ||||||
|   | |||||||
| @@ -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 |         // 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 (noteTreeId === globalNote.detail.note_id || noteContentId === globalNote.detail.note_id) { | ||||||
|             // if it's already there, remove the note |             // 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); |             recentNotes.unshift(noteTreeId); | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -26,7 +26,16 @@ function notecase2html(note) { | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         else if (el.type === 'link') { |         else if (el.type === 'link') { | ||||||
|             let linkHtml = '<a href="' + el.target_url + '">' + el.lnk_text + '</a>'; |             let targetUrl; | ||||||
|  |  | ||||||
|  |             if (el.target_url) { | ||||||
|  |                 targetUrl = el.target_url; | ||||||
|  |             } | ||||||
|  |             else { | ||||||
|  |                 targetUrl = "app#" + el.target_note_id; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             let 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); |             noteText = noteText.substr(0, el.note_offset + offset) + noteText.substr(el.note_offset + offset + el.lnk_text.length); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -33,6 +33,7 @@ ul.fancytree-container { | |||||||
|     outline: none !important; |     outline: none !important; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /* icons from https://feathericons.com */ | ||||||
| span.fancytree-node > span.fancytree-icon { | span.fancytree-node > span.fancytree-icon { | ||||||
|     background-position: 0 0; |     background-position: 0 0; | ||||||
|     background-image: url("icons/file.png"); |     background-image: url("icons/file.png"); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user