From c262a19205830e65de98a7633ae31c181bffb852 Mon Sep 17 00:00:00 2001 From: "Jeremy W. Sherman" Date: Mon, 19 Aug 2024 22:32:16 -0400 Subject: [PATCH] search: Match plaintext case-insensitively [fix #27] --- _includes/search-dictionary.html | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/_includes/search-dictionary.html b/_includes/search-dictionary.html index f3db45c..a24ef0a 100644 --- a/_includes/search-dictionary.html +++ b/_includes/search-dictionary.html @@ -74,13 +74,14 @@ } } - function showAllExamplesOfEntriesWithPlaintextMatching(query) { - const showAll = query === '' + function showAllExamplesOfEntriesWithPlaintextMatching(/** @type{string} */query) { + const lowercaseTrimmedQuery = query.trim().toLowerCase() + const showAll = lowercaseTrimmedQuery === '' const anchors = document.querySelectorAll('a[data-plaintext]') let entryCount = 0 for (const anchor of anchors) { - const plaintext = anchor.dataset.plaintext.replaceAll('\\"', '"') - const isMatch = showAll || plaintext.includes(query) + const plaintext = anchor.dataset.plaintext.replaceAll('\\"', '"').toLowerCase() + const isMatch = showAll || plaintext.includes(lowercaseTrimmedQuery) const entry = anchor.closest('li') if (isMatch) {