feature: add subscript and superscript extensions, docs and tests

This commit is contained in:
Hans Pagel
2021-06-01 16:18:25 +02:00
committed by Hans Pagel
parent 7387eaf51b
commit 3f57a13d19
16 changed files with 492 additions and 10 deletions

View File

@@ -0,0 +1,42 @@
context('/demos/Marks/Subscript', () => {
before(() => {
cy.visit('/demos/Marks/Subscript')
})
beforeEach(() => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p>Example Text</p>')
cy.get('.ProseMirror').type('{selectall}')
})
})
it('should transform inline style to sub tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p><span style="vertical-align: middle">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><sub>Example Text</sub></p>')
})
})
it('sould omit inline style with a different vertical align', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p><b style="vertical-align: middle">Example Text</b></p>')
expect(editor.getHTML()).to.eq('<p>Example Text</p>')
})
})
it('the button should make the selected text bold', () => {
cy.get('button:first')
.click()
cy.get('.ProseMirror')
.find('sub')
.should('contain', 'Example Text')
})
it('the button should toggle the selected text bold', () => {
cy.get('button:first').click()
cy.get('.ProseMirror').type('{selectall}')
cy.get('button:first').click()
cy.get('.ProseMirror sub').should('not.exist')
})
})

View File

@@ -0,0 +1,49 @@
<template>
<div v-if="editor">
<button @click="editor.chain().focus().toggleSubscript().run()" :class="{ 'is-active': editor.isActive('subscript') }">
subscript
</button>
<editor-content :editor="editor" />
</div>
</template>
<script>
import { Editor, EditorContent } from '@tiptap/vue-2'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import Subscript from '@tiptap/extension-subscript'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document,
Paragraph,
Text,
Subscript,
],
content: `
<p>This is regular text.</p>
<p><sub>This is subscript.</sub></p>
<p><span style="vertical-align: sub">And this.</span></p>
`,
})
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>

View File

@@ -0,0 +1,42 @@
context('/demos/Marks/Superscript', () => {
before(() => {
cy.visit('/demos/Marks/Superscript')
})
beforeEach(() => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p>Example Text</p>')
cy.get('.ProseMirror').type('{selectall}')
})
})
it('should transform inline style to sup tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p><span style="vertical-align: super">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><sup>Example Text</sup></p>')
})
})
it('sould omit inline style with a different vertical align', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p><span style="vertical-align: middle">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p>Example Text</p>')
})
})
it('the button should make the selected text bold', () => {
cy.get('button:first')
.click()
cy.get('.ProseMirror')
.find('sup')
.should('contain', 'Example Text')
})
it('the button should toggle the selected text bold', () => {
cy.get('button:first').click()
cy.get('.ProseMirror').type('{selectall}')
cy.get('button:first').click()
cy.get('.ProseMirror sup').should('not.exist')
})
})

View File

@@ -0,0 +1,49 @@
<template>
<div v-if="editor">
<button @click="editor.chain().focus().toggleSuperscript().run()" :class="{ 'is-active': editor.isActive('superscript') }">
superscript
</button>
<editor-content :editor="editor" />
</div>
</template>
<script>
import { Editor, EditorContent } from '@tiptap/vue-2'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import Superscript from '@tiptap/extension-superscript'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document,
Paragraph,
Text,
Superscript,
],
content: `
<p>This is regular text.</p>
<p><sup>This is superscript.</sup></p>
<p><span style="vertical-align: super">And this.</span></p>
`,
})
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>