| 
									
										
										
										
											2025-08-19 21:32:08 +00:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Quick Search specific result renderer | 
					
						
							|  |  |  |  *  | 
					
						
							|  |  |  |  * This module provides HTML rendering functionality specifically for the Quick Search widget. | 
					
						
							|  |  |  |  * The Jump To dialog (note_autocomplete) intentionally has its own inline rendering logic | 
					
						
							|  |  |  |  * with different styling and layout requirements. | 
					
						
							|  |  |  |  *  | 
					
						
							|  |  |  |  * SECURITY NOTE: HTML Snippet Handling | 
					
						
							| 
									
										
										
										
											2025-08-20 19:46:49 +00:00
										 |  |  |  * The highlighted snippet fields (highlightedAttributeSnippet) contain | 
					
						
							| 
									
										
										
										
											2025-08-19 21:32:08 +00:00
										 |  |  |  * pre-sanitized HTML from the server. The server-side processing: | 
					
						
							|  |  |  |  * 1. Escapes all HTML using the escape-html library | 
					
						
							| 
									
										
										
										
											2025-08-20 19:46:49 +00:00
										 |  |  |  * 2. Adds safe HTML tags for display: <b> for search term highlighting | 
					
						
							| 
									
										
										
										
											2025-08-19 21:32:08 +00:00
										 |  |  |  * 3. See apps/server/src/services/search/services/search.ts for implementation | 
					
						
							|  |  |  |  *  | 
					
						
							|  |  |  |  * This means the HTML snippets can be safely inserted without additional escaping on the client side. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import type { Suggestion } from "./note_autocomplete.js"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Creates HTML for a Quick Search result item | 
					
						
							|  |  |  |  *  | 
					
						
							|  |  |  |  * @param result - The search result item to render | 
					
						
							|  |  |  |  * @returns HTML string formatted for Quick Search widget display | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export function createSearchResultHtml(result: Suggestion): string { | 
					
						
							|  |  |  |     // Handle command action
 | 
					
						
							|  |  |  |     if (result.action === "command") { | 
					
						
							|  |  |  |         let html = `<div class="command-suggestion">`; | 
					
						
							|  |  |  |         html += `<span class="command-icon ${result.icon || "bx bx-terminal"}"></span>`; | 
					
						
							|  |  |  |         html += `<div class="command-content">`; | 
					
						
							|  |  |  |         html += `<div class="command-name">${result.highlightedNotePathTitle || ''}</div>`; | 
					
						
							|  |  |  |         if (result.commandDescription) { | 
					
						
							|  |  |  |             html += `<div class="command-description">${result.commandDescription}</div>`; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         html += `</div>`; | 
					
						
							|  |  |  |         if (result.commandShortcut) { | 
					
						
							|  |  |  |             html += `<kbd class="command-shortcut">${result.commandShortcut}</kbd>`; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         html += '</div>'; | 
					
						
							|  |  |  |         return html; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-20 19:46:49 +00:00
										 |  |  |     // Default: render as note result
 | 
					
						
							| 
									
										
										
										
											2025-08-19 21:32:08 +00:00
										 |  |  |     // Wrap everything in a flex column container
 | 
					
						
							|  |  |  |     let itemHtml = `<div style="display: flex; flex-direction: column; gap: 2px;">`; | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     // Title row with icon
 | 
					
						
							|  |  |  |     itemHtml += `<div style="display: flex; align-items: center; gap: 6px;">`; | 
					
						
							|  |  |  |     itemHtml += `<span class="${result.icon || 'bx bx-note'}" style="flex-shrink: 0;"></span>`; | 
					
						
							|  |  |  |     itemHtml += `<span class="search-result-title" style="flex: 1;">${result.highlightedNotePathTitle || result.notePathTitle || ''}</span>`; | 
					
						
							|  |  |  |     itemHtml += `</div>`; | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2025-08-20 19:46:49 +00:00
										 |  |  |     // Add attribute snippet if available (inline display)
 | 
					
						
							| 
									
										
										
										
											2025-08-19 21:32:08 +00:00
										 |  |  |     if (result.highlightedAttributeSnippet && result.highlightedAttributeSnippet.trim()) { | 
					
						
							| 
									
										
										
										
											2025-08-20 19:46:49 +00:00
										 |  |  |         itemHtml += `<div class="search-result-attributes" style="margin-left: 20px; color: var(--muted-text-color); font-size: 0.9em;">${result.highlightedAttributeSnippet}</div>`; | 
					
						
							| 
									
										
										
										
											2025-08-19 21:32:08 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     itemHtml += `</div>`; | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     return itemHtml; | 
					
						
							|  |  |  | } |