From f6d7e00a746a67fa440a3fa0f5362295959873d2 Mon Sep 17 00:00:00 2001 From: bdbch <6538827+bdbch@users.noreply.github.com> Date: Thu, 14 Dec 2023 15:10:08 +0100 Subject: [PATCH] fix(typography): require spaces after divisions to not break date formats (#4696) --- demos/src/Extensions/Typography/React/index.spec.js | 9 +++++++++ packages/extension-typography/src/typography.ts | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/demos/src/Extensions/Typography/React/index.spec.js b/demos/src/Extensions/Typography/React/index.spec.js index a21227f02..b99b28223 100644 --- a/demos/src/Extensions/Typography/React/index.spec.js +++ b/demos/src/Extensions/Typography/React/index.spec.js @@ -9,6 +9,15 @@ context('/src/Extensions/Typography/React/', () => { }) }) + it('should keep dates as they are', () => { + cy.get('.tiptap').type('1/4/2024').should('contain', '1/4/2024') + }) + + it('should make a fraction only with spaces afterwards', () => { + cy.get('.tiptap').type('1/4').should('contain', '1/4') + cy.get('.tiptap').type('{selectall}{backspace}1/4 ').should('contain', '¼') + }) + it('should make an em dash from two dashes', () => { cy.get('.tiptap').type('-- emDash').should('contain', '— emDash') }) diff --git a/packages/extension-typography/src/typography.ts b/packages/extension-typography/src/typography.ts index 4ce2f08ef..1c37644df 100644 --- a/packages/extension-typography/src/typography.ts +++ b/packages/extension-typography/src/typography.ts @@ -86,7 +86,7 @@ export const registeredTrademark = (override?: string) => textInputRule({ }) export const oneHalf = (override?: string) => textInputRule({ - find: /(?:^|\s)(1\/2)$/, + find: /(?:^|\s)(1\/2)\s$/, replace: override ?? '½', }) @@ -126,12 +126,12 @@ export const superscriptThree = (override?: string) => textInputRule({ }) export const oneQuarter = (override?: string) => textInputRule({ - find: /(?:^|\s)(1\/4)$/, + find: /(?:^|\s)(1\/4)\s$/, replace: override ?? '¼', }) export const threeQuarters = (override?: string) => textInputRule({ - find: /(?:^|\s)(3\/4)$/, + find: /(?:^|\s)(3\/4)\s$/, replace: override ?? '¾', })