From 2a409beeb0475345ed48913918be541631b172d1 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Fri, 28 Oct 2022 13:19:05 +0200 Subject: [PATCH] Better highlighting --- src/tools/utils.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tools/utils.ts b/src/tools/utils.ts index 6207d6f..7fe47b8 100644 --- a/src/tools/utils.ts +++ b/src/tools/utils.ts @@ -65,9 +65,15 @@ export function getAllIndices(text: string, regex: RegExp): SearchMatch[] { .filter(isSearchMatch) } +/** + * Used to find excerpts in a note body, or select which words to highlight + */ export function stringsToRegex(strings: string[]): RegExp { 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(