Skip to content

Commit

Permalink
fix(decensor): improve handling of dollar symbol in decensor function
Browse files Browse the repository at this point in the history
- Implement counter to ensure each replacement is used once and in order
- Use global `g` flag in RegExp to handle all occurrences of the mask
  • Loading branch information
envico801 committed Sep 30, 2024
1 parent feb3db2 commit cea8ddb
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,12 @@ export class FormatConverter {
return [note_text.replace(regexp, mask), matches]
}

decensor(note_text: string, mask:string, replacements: string[], escape: boolean): string {
for (let replacement of replacements) {
note_text = note_text.replace(
mask, escape ? escapeHtml(replacement) : replacement
)
}
return note_text
decensor(note_text: string, mask: string, replacements: string[], escape: boolean): string {
let i = 0;
return note_text.replace(new RegExp(mask, 'g'), (): string => {
let replacement: string = replacements[i++];
return escape ? escapeHtml(replacement) : replacement;
});
}

format(note_text: string, cloze: boolean, highlights_to_cloze: boolean): string {
Expand Down

0 comments on commit cea8ddb

Please sign in to comment.