From d09c6649096379eb8cd084d58d3ea06f3bfb8d36 Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Thu, 8 Oct 2020 03:57:45 +0200 Subject: [PATCH] add italic parseDOM tests --- .../src/demos/Extensions/Italic/index.spec.js | 21 +++++++++++++++++++ packages/extension-italic/index.ts | 13 +++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/docs/src/demos/Extensions/Italic/index.spec.js b/docs/src/demos/Extensions/Italic/index.spec.js index 0bd952ac..27505e00 100644 --- a/docs/src/demos/Extensions/Italic/index.spec.js +++ b/docs/src/demos/Extensions/Italic/index.spec.js @@ -10,6 +10,27 @@ context('/api/extensions/italic', () => { }) }) + it('i tags should be transformed to em tags', () => { + cy.get('.ProseMirror').then(([{ editor }]) => { + editor.setContent('

Example Text

') + expect(editor.html()).to.eq('

Example Text

') + }) + }) + + it('i tags with normal font style should be omitted', () => { + cy.get('.ProseMirror').then(([{ editor }]) => { + editor.setContent('

Example Text

') + expect(editor.html()).to.eq('

Example Text

') + }) + }) + + it('generic tags with italic style should be transformed to strong tags', () => { + cy.get('.ProseMirror').then(([{ editor }]) => { + editor.setContent('

Example Text

') + expect(editor.html()).to.eq('

Example Text

') + }) + }) + it('the button should make the selected text italic', () => { cy.get('.demo__preview button:first') .click() diff --git a/packages/extension-italic/index.ts b/packages/extension-italic/index.ts index e6021921..bbc2ef42 100644 --- a/packages/extension-italic/index.ts +++ b/packages/extension-italic/index.ts @@ -19,9 +19,16 @@ export default new Mark() .name('italic') .schema(() => ({ parseDOM: [ - { tag: 'i' }, - { tag: 'em' }, - { style: 'font-style=italic' }, + { + tag: 'em', + }, + { + tag: 'i', + getAttrs: node => (node as HTMLElement).style.fontStyle !== 'normal' && null, + }, + { + style: 'font-style=italic', + }, ], toDOM: () => ['em', 0], }))