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 | ||||
|  | ||||
| def insert(tablename, rec): | ||||
|     # FIXME: SQL injection! | ||||
|     keys = ','.join(rec.keys()) | ||||
|     question_marks = ','.join(list('?'*len(rec))) | ||||
|     values = tuple(rec.values()) | ||||
|   | ||||
| @@ -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 = /^<a[^>]+?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 = /<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) { | ||||
|                 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++; | ||||
|   | ||||
| @@ -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); | ||||
|         } | ||||
|   | ||||
| @@ -26,7 +26,16 @@ function notecase2html(note) { | ||||
|             } | ||||
|         } | ||||
|         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); | ||||
|  | ||||
|   | ||||
| @@ -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"); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user