autoformat-kit
plate/autoformat-kitFreeComponent
plate publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by plate on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://platejs.org/r/autoformat-kit.jsonSource
1'use client';23import type { SlateEditor } from 'platejs';45import {6 createSlatePlugin,7 createTextSubstitutionInputRule,8 KEYS,9} from 'platejs';1011const isTextSubstitutionBlocked = (editor: SlateEditor) =>12 editor.api.some({13 match: {14 type: [editor.getType(KEYS.codeBlock)],15 },16 });1718const createAutoformatTextSubstitutionRule = ({19 patterns,20}: {21 patterns: Parameters<typeof createTextSubstitutionInputRule>[0]['patterns'];22}) =>23 createTextSubstitutionInputRule({24 enabled: ({ editor }) => !isTextSubstitutionBlocked(editor),25 patterns,26 });2728const arrowsRule = createAutoformatTextSubstitutionRule({29 patterns: [30 { format: '→', match: '->' },31 { format: '←', match: '<-' },32 { format: '⇒', match: '=>' },33 { format: '⇐', match: ['<=', '≤='] },34 ],35});3637const comparisonsRule = createAutoformatTextSubstitutionRule({38 patterns: [39 { format: '≯', match: '!>' },40 { format: '≮', match: '!<' },41 { format: '≥', match: '>=' },42 { format: '≤', match: '<=' },43 { format: '≱', match: '!>=' },44 { format: '≰', match: '!<=' },45 ],46});4748const equalityRule = createAutoformatTextSubstitutionRule({49 patterns: [50 { format: '≠', match: '!=' },51 { format: '≡', match: '==' },52 { format: '≢', match: ['!==', '≠='] },53 { format: '≈', match: '~=' },54 { format: '≉', match: '!~=' },55 ],56});5758const fractionsRule = createAutoformatTextSubstitutionRule({59 patterns: [60 { format: '½', match: '1/2' },61 { format: '⅓', match: '1/3' },62 { format: '¼', match: '1/4' },63 { format: '⅕', match: '1/5' },64 { format: '⅙', match: '1/6' },65 { format: '⅐', match: '1/7' },66 { format: '⅛', match: '1/8' },67 { format: '⅑', match: '1/9' },68 { format: '⅒', match: '1/10' },69 { format: '⅔', match: '2/3' },70 { format: '⅖', match: '2/5' },71 { format: '¾', match: '3/4' },72 { format: '⅗', match: '3/5' },73 { format: '⅜', match: '3/8' },74 { format: '⅘', match: '4/5' },75 { format: '⅚', match: '5/6' },76 { format: '⅝', match: '5/8' },77 { format: '⅞', match: '7/8' },78 ],79});8081const legalRule = createAutoformatTextSubstitutionRule({82 patterns: [83 { format: '™', match: ['(tm)', '(TM)'] },84 { format: '®', match: ['(r)', '(R)'] },85 { format: '©', match: ['(c)', '(C)'] },86 ],87});8889const legalHtmlRule = createAutoformatTextSubstitutionRule({90 patterns: [91 { format: '™', match: '™' },92// … truncated
What it pulls in
npm packages
Files it writes
More from plate
All 324 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-kitai-kit | plate | Components | Free | 1 dep | |
| AI Menuai-menu | plate | Components | Free | 5 deps · 2 files | |
| AI Leafai-node | plate | Components | Free | no deps | |
| AI Toolbar Buttonai-toolbar-button | plate | Components | Free | 1 dep | |
| align-base-kitalign-base-kit | plate | Components | Free | 1 dep | |
| align-kitalign-kit | plate | Components | Free | 1 dep | |
| Align Toolbar Buttonalign-toolbar-button | plate | Components | Free | 1 dep | |
| autoformat-classic-kitautoformat-classic-kit | plate | Components | Free | 2 deps |
