Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add distinctive highlight-based clozing #133

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/services/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,21 @@ export class Parser {
});

// Replace the highlight clozes in the line with Anki syntax
clozeText = clozeText.replace(this.regex.singleClozeHighlight, "{{c1::$2}}");
// increment c1, c2, c3, etc. as regex greedily replaces for every match in the regex
// example: clozeText = clozeText.replace(this.regex.singleClozeHighlight, "{{c1::$2}}");

let clozeNumber = 1;
// loop through all the clozes in the line
for (const cloze of clozeText.matchAll(this.regex.singleClozeHighlight)) {
// if the cloze is not in a math block, then replace it with Anki syntax
const globalOffset = matchIndex + cloze.index;
const isInMathBlock = rangesToDiscard.some(x => (globalOffset >= x[0] && globalOffset + cloze[0].length <= x[1]));
if (!isInMathBlock) {
clozeText = clozeText.replace(cloze[0], `{{c${clozeNumber}::${cloze[2]}}}`);
clozeNumber++;
}
}


if (clozeText === match[2]) {
// If the clozeText is the same as the match it means that the curly clozes were all in math blocks
Expand Down