Skip to content

Commit

Permalink
Fix brackets before term matches
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvNC committed Dec 23, 2023
1 parent 4466a96 commit 0f64cbe
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/readingParse.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ function getReadingFromDefinition(definition, term) {
term = term.replace(/ /g, '');
const bracketRegex = /([((]([^))]*))/g;
const bracketMatches = bracketRegex.exec(definition);

if (bracketMatches && bracketMatches.length >= 2) {
// @ts-ignore
const outerBracketContent = bracketMatches[1];
const bracketContent = bracketMatches[2];
// Check if the bracket is at the beginning of the definition or closely following the term
const bracketIndex = definition.indexOf(outerBracketContent);
const termIndex = definition.indexOf(term) ?? 0;
const termEndIndex = termIndex + term.length;
// If the bracket is not at the beginning of the definition or closely following the term, ignore it
if (bracketIndex - termEndIndex > leewayAfterTerm) {
return '';
}
// If the bracket is within the term or before the term, ignore it
if (bracketIndex < termIndex) {
return '';
}
return parseReadingFromBrackets(bracketContent, term);
}
return '';
Expand Down

0 comments on commit 0f64cbe

Please sign in to comment.