Better highlighting

This commit is contained in:
Simon Cambier
2022-10-28 13:19:05 +02:00
parent 9af71e3efc
commit 2a409beeb0

View File

@@ -65,9 +65,15 @@ export function getAllIndices(text: string, regex: RegExp): SearchMatch[] {
.filter(isSearchMatch) .filter(isSearchMatch)
} }
/**
* Used to find excerpts in a note body, or select which words to highlight
*/
export function stringsToRegex(strings: string[]): RegExp { export function stringsToRegex(strings: string[]): RegExp {
if (!strings.length) return /^$/g if (!strings.length) return /^$/g
return new RegExp(strings.map(s => `(${escapeRegex(s)})`).join('|'), 'gi') const joined = strings.map(s => escapeRegex(s)).join('|')
const reg = new RegExp(`(${joined})`, 'gi')
// console.log(reg)
return reg
} }
export function extractHeadingsFromCache( export function extractHeadingsFromCache(