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], }))