-
-
Notifications
You must be signed in to change notification settings - Fork 742
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
feat: support regex in auto format plugin #3426
Conversation
🦋 Changeset detectedLatest commit: eaad154 The changes in this PR will be included in the next version bump. This PR includes changesets to release 57 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Not sure why the build fails |
|
@@ -23,7 +23,8 @@ export const autoformatIndentLists: AutoformatRule[] = [ | |||
toggleIndentList(editor, { | |||
listStyleType: ListStyleType.Decimal, | |||
}), | |||
match: ['1. ', '1) '], | |||
match: ['^\\d+\\.$ ', '^\\d+\\)$ '], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use RegExp literals here to avoid the need for extra backslashes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds better but I am afraid it could involve a giant refactor
plate/packages/autoformat/src/utils/getMatchRange.ts
Lines 23 to 25 in 342ff1e
const triggers: string[] = trigger ? castArray(trigger) : [end.slice(-1)]; | |
end = trigger ? end : end.slice(0, -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it does a slice to extract the last character as the trigger to match, and others are used to match. We cannot use regex to do that. A conversion regex -> string -> slice -> regex is still needed, or we need to refactor a lot.
Checklist
yarn typecheck
yarn lint:fix
yarn test
yarn brl
yarn changeset
#3422