Skip to content

Commit

Permalink
fix(typography): require spaces after divisions to not break date for…
Browse files Browse the repository at this point in the history
…mats
  • Loading branch information
bdbch committed Dec 14, 2023
1 parent e66160d commit bf7ff81
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions demos/src/Extensions/Typography/React/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand Down
6 changes: 3 additions & 3 deletions packages/extension-typography/src/typography.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? '½',
})

Expand Down Expand Up @@ -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 ?? '¾',
})

Expand Down

0 comments on commit bf7ff81

Please sign in to comment.