From 2bd9dea91d67440f43c68a4eceef2fc68ad4f384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20Jim=C3=A9nez?= Date: Sat, 24 Aug 2024 10:23:04 +0000 Subject: [PATCH] Implement new logic for accent conversion in search field --- src/fragmentarium/domain/normalizeAccents.test.ts | 2 ++ src/fragmentarium/domain/normalizeAccents.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/fragmentarium/domain/normalizeAccents.test.ts b/src/fragmentarium/domain/normalizeAccents.test.ts index 5096ef8b3..c90b5bd14 100644 --- a/src/fragmentarium/domain/normalizeAccents.test.ts +++ b/src/fragmentarium/domain/normalizeAccents.test.ts @@ -14,6 +14,8 @@ test.each([ ['PÈL', 'PEL₃'], ['LÚ', 'LU₂'], ['ÀMA', 'AMA₃'], + ['ÀM]A', 'AM]A₃'], + ['ÀM[A', 'AM[A₃'], ['ÀMA.KÚR', 'AMA₃.KUR₂'], ['LÌ gí-la-ka₃', 'LI₃ gi₂-la-ka₃'], ])('%s', (character, replacement) => { diff --git a/src/fragmentarium/domain/normalizeAccents.ts b/src/fragmentarium/domain/normalizeAccents.ts index 338db8879..7106c42f5 100644 --- a/src/fragmentarium/domain/normalizeAccents.ts +++ b/src/fragmentarium/domain/normalizeAccents.ts @@ -10,8 +10,10 @@ const specialTransliterationCharactersAsString = escapeRegExp( specialTransliterationCharacters ) +const spaceCharacters = '[^\\{\\}\\-\\.:,\\+\\s\\n]' + const accentExpression = new RegExp( - `(${charactersWithAccentsAsString})(${specialTransliterationCharactersAsString}|)\\w*`, + `(${charactersWithAccentsAsString})(${specialTransliterationCharactersAsString}|)${spaceCharacters}*`, 'g' ) @@ -25,6 +27,9 @@ export default function normalizeAccents(userInput: string): string { .split('') .map((character) => charactersWithAccents[character]?.letter ?? character) - return characterWithoutAccent.concat(subindex).join('') + // Check if the characterWithoutAccent contains an index + const index = subindex.length > 0 ? subindex.join('') : '' + + return characterWithoutAccent.concat(index).join('') }) }