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

feat: support regex in auto format plugin #3426

Merged
merged 4 commits into from
Aug 14, 2024

Conversation

yf-yang
Copy link
Collaborator

@yf-yang yf-yang commented Aug 13, 2024

Checklist

  • yarn typecheck
  • yarn lint:fix
  • yarn test
  • yarn brl
  • yarn changeset
  • ui changelog

#3422

Copy link

changeset-bot bot commented Aug 13, 2024

🦋 Changeset detected

Latest commit: eaad154

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 57 packages
Name Type
@udecode/plate-autoformat Major
@udecode/slate-utils Major
@udecode/plate Major
@udecode/plate-common Major
@udecode/plate-core Major
@udecode/plate-utils Major
@udecode/plate-alignment Major
@udecode/plate-basic-elements Major
@udecode/plate-basic-marks Major
@udecode/plate-block-quote Major
@udecode/plate-break Major
@udecode/plate-callout Major
@udecode/plate-caption Major
@udecode/plate-cloud Major
@udecode/plate-code-block Major
@udecode/plate-combobox Major
@udecode/plate-comments Major
@udecode/plate-cursor Major
@udecode/plate-diff Major
@udecode/plate-dnd Major
@udecode/plate-emoji Major
@udecode/plate-excalidraw Major
@udecode/plate-find-replace Major
@udecode/plate-floating Major
@udecode/plate-font Major
@udecode/plate-heading Major
@udecode/plate-highlight Major
@udecode/plate-horizontal-rule Major
@udecode/plate-indent-list Major
@udecode/plate-indent Major
@udecode/plate-juice Major
@udecode/plate-kbd Major
@udecode/plate-layout Major
@udecode/plate-line-height Major
@udecode/plate-link Major
@udecode/plate-list Major
@udecode/plate-math Major
@udecode/plate-media Major
@udecode/plate-mention Major
@udecode/plate-node-id Major
@udecode/plate-normalizers Major
@udecode/plate-paragraph Major
@udecode/plate-reset-node Major
@udecode/plate-resizable Major
@udecode/plate-select Major
@udecode/plate-selection Major
@udecode/plate-serializer-csv Major
@udecode/plate-serializer-docx Major
@udecode/plate-serializer-html Major
@udecode/plate-serializer-md Major
@udecode/plate-slash-command Major
@udecode/plate-suggestion Major
@udecode/plate-tabbable Major
@udecode/plate-table Major
@udecode/plate-toggle Major
@udecode/plate-trailing-block Major
@udecode/plate-yjs Major

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

Copy link

vercel bot commented Aug 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
plate ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 14, 2024 2:01am

@yf-yang
Copy link
Collaborator Author

yf-yang commented Aug 13, 2024

Not sure why the build fails

@12joan
Copy link
Collaborator

12joan commented Aug 13, 2024

Not sure why the build fails

templates/plate-playground-template uses the versions of Plate packages published to NPM and shouldn't be modified in PRs.

@@ -23,7 +23,8 @@ export const autoformatIndentLists: AutoformatRule[] = [
toggleIndentList(editor, {
listStyleType: ListStyleType.Decimal,
}),
match: ['1. ', '1) '],
match: ['^\\d+\\.$ ', '^\\d+\\)$ '],
Copy link
Collaborator

@12joan 12joan Aug 13, 2024

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?

Copy link
Collaborator Author

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

const triggers: string[] = trigger ? castArray(trigger) : [end.slice(-1)];
end = trigger ? end : end.slice(0, -1);

Copy link
Collaborator Author

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.

@yf-yang yf-yang requested a review from zbeyens August 14, 2024 02:00
@zbeyens zbeyens merged commit 8737579 into udecode:main Aug 14, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants