| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  | function notecase2html(note) { | 
					
						
							|  |  |  |     let noteText = note.detail.note_text; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-25 00:00:08 -04:00
										 |  |  |     note.formatting.forEach(el => el.type = 'formatting'); | 
					
						
							|  |  |  |     note.links.forEach(el => el.type = 'link'); | 
					
						
							|  |  |  |     note.images.forEach(el => el.type = 'image'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-29 22:25:58 -04:00
										 |  |  |     const allTags = note.formatting.concat(note.links).concat(note.images); | 
					
						
							|  |  |  |     allTags.sort(function compare(a, b) { | 
					
						
							| 
									
										
										
										
											2017-08-25 19:30:26 -04:00
										 |  |  |         return a.note_offset - b.note_offset; | 
					
						
							| 
									
										
										
										
											2017-08-25 00:00:08 -04:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     let offset = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function inject(target, injected, position) { | 
					
						
							|  |  |  |         offset += injected.length; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return noteText.substr(0, position) + injected + noteText.substr(position); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-29 22:25:58 -04:00
										 |  |  |     for (const el of allTags) { | 
					
						
							| 
									
										
										
										
											2017-08-25 00:00:08 -04:00
										 |  |  |         if (el.type === 'formatting') { | 
					
						
							|  |  |  |             if (tags[el.fmt_tag]) { | 
					
						
							|  |  |  |                 noteText = inject(noteText, tags[el.fmt_tag], el.note_offset + offset); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-08-25 00:00:08 -04:00
										 |  |  |         else if (el.type === 'link') { | 
					
						
							| 
									
										
										
										
											2017-08-27 14:39:26 -04:00
										 |  |  |             let targetUrl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (el.target_url) { | 
					
						
							|  |  |  |                 targetUrl = el.target_url; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else { | 
					
						
							|  |  |  |                 targetUrl = "app#" + el.target_note_id; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-29 22:25:58 -04:00
										 |  |  |             const linkHtml = '<a href="' + targetUrl + '">' + el.lnk_text + '</a>'; | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-25 00:00:08 -04:00
										 |  |  |             noteText = noteText.substr(0, el.note_offset + offset) + noteText.substr(el.note_offset + offset + el.lnk_text.length); | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-25 00:00:08 -04:00
										 |  |  |             noteText = inject(noteText, linkHtml, el.note_offset + offset); | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-25 00:00:08 -04:00
										 |  |  |             offset -= el.lnk_text.length; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (el.type === 'image') { | 
					
						
							| 
									
										
										
										
											2017-08-29 22:25:58 -04:00
										 |  |  |             const type = el.is_png ? "png" : "jpg"; | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-29 22:25:58 -04:00
										 |  |  |             const imgHtml = '<img alt="Embedded Image" src="data:image/' + type + ';base64,' + el.image_data + '" />'; | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-25 00:00:08 -04:00
										 |  |  |             noteText = inject(noteText, imgHtml, el.note_offset + offset); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-25 20:40:33 -04:00
										 |  |  |     noteText = noteText.replace(/(?:\r\n|\r)/g, '\n'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     noteText = noteText.replace(/(.+)\n/g, '<p>$1</p>'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     noteText = noteText.replace(/\n/g, '<p><br></p>'); | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-13 21:42:10 -04:00
										 |  |  |     noteText = noteText.replace(/  /g, '  '); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  |     return noteText; | 
					
						
							|  |  |  | } |