add mark demos

This commit is contained in:
Philipp Kühn
2021-08-25 18:07:36 +02:00
parent 88804668ff
commit 502b533f60
30 changed files with 1402 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<div id="app"></div>
<script type="module">
import setup from '../../../../setup/vue.ts'
import source from '@source'
setup('Marks/Bold', source)
</script>
</body>
</html>

View File

@@ -0,0 +1,91 @@
context('/demos/Marks/Bold', () => {
before(() => {
cy.visit('/demos/Marks/Bold')
})
beforeEach(() => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p>Example Text</p>')
cy.get('.ProseMirror').type('{selectall}')
})
})
it('should transform b tags to strong tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p><b>Example Text</b></p>')
expect(editor.getHTML()).to.eq('<p><strong>Example Text</strong></p>')
})
})
it('sould omit b tags with normal font weight inline style', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p><b style="font-weight: normal">Example Text</b></p>')
expect(editor.getHTML()).to.eq('<p>Example Text</p>')
})
})
it('should transform any tag with bold inline style to strong tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p><span style="font-weight: bold">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><strong>Example Text</strong></p>')
editor.commands.setContent('<p><span style="font-weight: bolder">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><strong>Example Text</strong></p>')
editor.commands.setContent('<p><span style="font-weight: 500">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><strong>Example Text</strong></p>')
editor.commands.setContent('<p><span style="font-weight: 900">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><strong>Example Text</strong></p>')
})
})
it('the button should make the selected text bold', () => {
cy.get('button:first')
.click()
cy.get('.ProseMirror')
.find('strong')
.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 strong').should('not.exist')
})
it('should make the selected text bold when the keyboard shortcut is pressed', () => {
cy.get('.ProseMirror')
.trigger('keydown', { modKey: true, key: 'b' })
.find('strong')
.should('contain', 'Example Text')
})
it('should toggle the selected text bold when the keyboard shortcut is pressed', () => {
cy.get('.ProseMirror')
.trigger('keydown', { modKey: true, key: 'b' })
.find('strong')
.should('contain', 'Example Text')
cy.get('.ProseMirror')
.trigger('keydown', { modKey: true, key: 'b' })
cy.get('.ProseMirror strong').should('not.exist')
})
it('should make a bold text from the default markdown shortcut', () => {
cy.get('.ProseMirror')
.type('**Bold**')
.find('strong')
.should('contain', 'Bold')
})
it('should make a bold text from the alternative markdown shortcut', () => {
cy.get('.ProseMirror')
.type('__Bold__')
.find('strong')
.should('contain', 'Bold')
})
})

View File

@@ -0,0 +1,53 @@
<template>
<div v-if="editor">
<button @click="editor.chain().focus().toggleBold().run()" :class="{ 'is-active': editor.isActive('bold') }">
bold
</button>
<editor-content :editor="editor" />
</div>
</template>
<script>
import { Editor, EditorContent } from '@tiptap/vue-3'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import Bold from '@tiptap/extension-bold'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document,
Paragraph,
Text,
Bold,
],
content: `
<p>This isnt bold.</p>
<p><strong>This is bold.</strong></p>
<p><b>And this.</b></p>
<p style="font-weight: bold">This as well.</p>
<p style="font-weight: bolder">Oh, and this!</p>
<p style="font-weight: 500">Cool, isnt it!?</p>
<p style="font-weight: 999">Up to font weight 999!!!</p>
`,
})
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>