Skip to content

Commit

Permalink
implement #372
Browse files Browse the repository at this point in the history
  • Loading branch information
mProjectsCode committed Jul 5, 2024
1 parent 8d09e7c commit 933b47b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/core/src/config/ButtonConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export interface ReplaceSelfButtonAction {
export interface RegexpReplaceInNoteButtonAction {
type: ButtonActionType.REGEXP_REPLACE_IN_NOTE;
regexp: string;
regexpFlags?: string;
replacement: string;
}

Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/config/ButtonConfigValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ export const V_RegexpReplaceInNoteButtonAction = schemaForType<RegexpReplaceInNo
z.object({
type: z.literal(ButtonActionType.REGEXP_REPLACE_IN_NOTE),
regexp: stringValidator('regexpReplaceInNote', 'regexp', 'search regular expression'),
regexpFlags: stringValidator(
'regexpReplaceInNote',
'regexpFlags',
'regular expression flags string',
).optional(),
replacement: stringValidator('regexpReplaceInNote', 'replacement', 'replacement string'),
}),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/fields/button/ButtonActionRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export class ButtonActionRunner {

let content = await this.plugin.internal.readFilePath(filePath);

content = content.replace(new RegExp(action.regexp, 'g'), action.replacement);
content = content.replace(new RegExp(action.regexp, action.regexpFlags ?? 'g'), action.replacement);

await this.plugin.internal.writeFilePath(filePath, content);
}
Expand Down

0 comments on commit 933b47b

Please sign in to comment.