From 2220c22e855d5a11077d2ceb18acbc7f459232a0 Mon Sep 17 00:00:00 2001 From: Sander Date: Tue, 12 Nov 2024 21:53:42 +0100 Subject: [PATCH 1/3] Preserved quotes in font-family parsing for fonts with spaces and numbers Removed the quote removal step in font-family parsing to support fonts that contain both spaces and numbers, such as "Exo 2", which require quotes for proper recognition. --- demos/src/Extensions/FontFamily/React/index.jsx | 16 ++++++++++++++-- .../extension-font-family/src/font-family.ts | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/demos/src/Extensions/FontFamily/React/index.jsx b/demos/src/Extensions/FontFamily/React/index.jsx index 41ef25bde2b..3d1fa851c78 100644 --- a/demos/src/Extensions/FontFamily/React/index.jsx +++ b/demos/src/Extensions/FontFamily/React/index.jsx @@ -18,6 +18,7 @@ export default () => {

The cool kids can apply monospace fonts aswell.

But hopefully we all can agree, that cursive fonts are the best.

Then there are CSS variables, the new hotness.

+

TipTap even can handle exotic fonts as Exo 2.

`, }) @@ -27,6 +28,9 @@ export default () => { return ( <> +
- +
- + ) } diff --git a/packages/extension-font-family/src/font-family.ts b/packages/extension-font-family/src/font-family.ts index b4f99a282e6..ac57f521c53 100644 --- a/packages/extension-font-family/src/font-family.ts +++ b/packages/extension-font-family/src/font-family.ts @@ -49,7 +49,7 @@ export const FontFamily = Extension.create({ attributes: { fontFamily: { default: null, - parseHTML: element => element.style.fontFamily?.replace(/['"]+/g, ''), + parseHTML: element => element.style.fontFamily, renderHTML: attributes => { if (!attributes.fontFamily) { return {} From 4ec1f9d56b914c16eb24965921efdc9125c22333 Mon Sep 17 00:00:00 2001 From: Sander Date: Tue, 12 Nov 2024 21:55:53 +0100 Subject: [PATCH 2/3] Added a test to ensure proper handling of font-family values that include both spaces and numbers, such as "Exo 2". --- demos/src/Extensions/FontFamily/React/index.spec.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/demos/src/Extensions/FontFamily/React/index.spec.js b/demos/src/Extensions/FontFamily/React/index.spec.js index eee77683a4e..03bfe5677bb 100644 --- a/demos/src/Extensions/FontFamily/React/index.spec.js +++ b/demos/src/Extensions/FontFamily/React/index.spec.js @@ -46,4 +46,12 @@ context('/src/Extensions/FontFamily/React/', () => { cy.get('.tiptap').find('span').should('have.attr', 'style', 'font-family: var(--title-font-family)') }) + it('should allow fonts containing a space and number as a font-family', () => { + cy.get('[data-test-id="exo2"]') + .should('not.have.class', 'is-active') + .click() + .should('have.class', 'is-active') + + cy.get('.tiptap').find('span').should('have.attr', 'style', 'font-family: "Exo 2"') + }) }) From c9a91968ba8febbd8f08ac5409e9bc1fcb34df4d Mon Sep 17 00:00:00 2001 From: Nick Perez Date: Sun, 17 Nov 2024 14:55:25 +0100 Subject: [PATCH 3/3] chore: add changeset --- .changeset/tiny-buckets-behave.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tiny-buckets-behave.md diff --git a/.changeset/tiny-buckets-behave.md b/.changeset/tiny-buckets-behave.md new file mode 100644 index 00000000000..c288572bbff --- /dev/null +++ b/.changeset/tiny-buckets-behave.md @@ -0,0 +1,5 @@ +--- +"@tiptap/extension-font-family": patch +--- + +Font-family extension: Prevent removal of quotes in parseHTML