| 14 | } |
| 15 | |
| 16 | export function formatResult(suggestion: Suggestion, currentValue: string): string { |
| 17 | if (!currentValue) { |
| 18 | // Same escaping channel as formatGroup — let the browser handle entities |
| 19 | // so an HTML-bearing suggestion.value can't break out of the text node. |
| 20 | const span = document.createElement("span"); |
| 21 | span.textContent = suggestion.value; |
| 22 | return span.innerHTML; |
| 23 | } |
| 24 | |
| 25 | const pattern = "(" + utils.escapeRegExChars(currentValue) + ")"; |
| 26 | |
| 27 | return suggestion.value |
| 28 | .replace(new RegExp(pattern, "gi"), "<strong>$1</strong>") |
| 29 | .replace(/&/g, "&") |
| 30 | .replace(/</g, "<") |
| 31 | .replace(/>/g, ">") |
| 32 | .replace(/"/g, """) |
| 33 | .replace(/<(\/?strong)>/g, "<$1>"); |
| 34 | } |
| 35 | |
| 36 | export function formatGroup(_suggestion: Suggestion, category: string): string { |
| 37 | const div = document.createElement("div"); |