Merge branch 'main' into feature/new-highlight-extension

# Conflicts:
#	packages/core/src/commands/toggleMark.ts
This commit is contained in:
Hans Pagel
2020-10-27 20:36:22 +01:00
164 changed files with 4827 additions and 2779 deletions

View File

@@ -10,6 +10,20 @@ context('/api/extensions/blockquote', () => {
})
})
it('should parse blockquote tags correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<blockquote><p>Example Text</p></blockquote>')
expect(editor.getHTML()).to.eq('<blockquote><p>Example Text</p></blockquote>')
})
})
it('should parse blockquote tags without paragraphs correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<blockquote>Example Text</blockquote>')
expect(editor.getHTML()).to.eq('<blockquote><p>Example Text</p></blockquote>')
})
})
it('the button should make the selected line a blockquote', () => {
cy.get('.ProseMirror blockquote')
.should('not.exist')

View File

@@ -10,6 +10,36 @@ context('/api/extensions/bold', () => {
})
})
it('should transform b tags to strong tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.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.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.setContent('<p><span style="font-weight: bold">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><strong>Example Text</strong></p>')
editor.setContent('<p><span style="font-weight: bolder">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><strong>Example Text</strong></p>')
editor.setContent('<p><span style="font-weight: 500">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><strong>Example Text</strong></p>')
editor.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('.demo__preview button:first')
.click()

View File

@@ -10,6 +10,20 @@ context('/api/extensions/bullet-list', () => {
})
})
it('should parse unordered lists correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<ul><li><p>Example Text</p></li></ul>')
expect(editor.getHTML()).to.eq('<ul><li><p>Example Text</p></li></ul>')
})
})
it('should parse unordered lists without paragraphs correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<ul><li>Example Text</li></ul>')
expect(editor.getHTML()).to.eq('<ul><li><p>Example Text</p></li></ul>')
})
})
it('the button should make the selected line a bullet list item', () => {
cy.get('.ProseMirror ul')
.should('not.exist')

View File

@@ -10,6 +10,16 @@ context('/api/extensions/code', () => {
})
})
it('should parse code tags correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><code>Example Text</code></p>')
expect(editor.getHTML()).to.eq('<p><code>Example Text</code></p>')
editor.setContent('<code>Example Text</code>')
expect(editor.getHTML()).to.eq('<p><code>Example Text</code></p>')
})
})
it('should mark the selected text as inline code', () => {
cy.get('.demo__preview button:first')
.click()
@@ -32,4 +42,11 @@ context('/api/extensions/code', () => {
cy.get('.ProseMirror code')
.should('not.exist')
})
it('should make inline code from the markdown shortcut', () => {
cy.get('.ProseMirror')
.type('`Example`')
.find('code')
.should('contain', 'Example')
})
})

View File

@@ -10,6 +10,20 @@ context('/api/extensions/code-block', () => {
})
})
it('should parse code blocks correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<pre><code>Example Text</code></pre>')
expect(editor.getHTML()).to.eq('<pre><code>Example Text</code></pre>')
})
})
it('should parse code blocks with language correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<pre><code class="language-css">Example Text</code></pre>')
expect(editor.getHTML()).to.eq('<pre><code class="language-css">Example Text</code></pre>')
})
})
it('the button should make the selected line a code block', () => {
cy.get('.demo__preview button:first')
.click()
@@ -39,36 +53,25 @@ context('/api/extensions/code-block', () => {
it('the keyboard shortcut should make the selected line a code block', () => {
cy.get('.ProseMirror')
.trigger('keydown', { shiftKey: true, ctrlKey: true, key: '\\' })
.trigger('keydown', { shiftKey: true, modKey: true, key: 'c' })
.find('pre')
.should('contain', 'Example Text')
})
it('the keyboard shortcut should toggle the code block', () => {
cy.get('.ProseMirror')
.trigger('keydown', { shiftKey: true, ctrlKey: true, key: '\\' })
.trigger('keydown', { shiftKey: true, modKey: true, key: 'c' })
.find('pre')
.should('contain', 'Example Text')
cy.get('.ProseMirror')
.type('{selectall}')
.trigger('keydown', { shiftKey: true, ctrlKey: true, key: '\\' })
.trigger('keydown', { shiftKey: true, modKey: true, key: 'c' })
cy.get('.ProseMirror pre')
.should('not.exist')
})
it('should make a code block from markdown shortcuts', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.clearContent()
cy.get('.ProseMirror')
.type('``` Code')
.find('pre>code')
.should('contain', 'Code')
})
})
it('should parse the language from a HTML code block', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<pre><code class="language-css">body { display: none; }</code></pre>')
@@ -79,7 +82,29 @@ context('/api/extensions/code-block', () => {
})
})
it('should make a code block for js', () => {
it('should make a code block from backtick markdown shortcuts', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.clearContent()
cy.get('.ProseMirror')
.type('``` Code')
.find('pre>code')
.should('contain', 'Code')
})
})
it('should make a code block from tilde markdown shortcuts', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.clearContent()
cy.get('.ProseMirror')
.type('~~~ Code')
.find('pre>code')
.should('contain', 'Code')
})
})
it('should make a code block for js with backticks', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.clearContent()
@@ -89,4 +114,15 @@ context('/api/extensions/code-block', () => {
.should('contain', 'Code')
})
})
it('should make a code block for js with tildes', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.clearContent()
cy.get('.ProseMirror')
.type('~~~js Code')
.find('pre>code.language-js')
.should('contain', 'Code')
})
})
})

View File

@@ -2,4 +2,25 @@ context('/api/extensions/document', () => {
before(() => {
cy.visit('/api/extensions/document')
})
beforeEach(() => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p></p>')
})
})
it('should return the document in as json', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
const json = editor.getJSON()
expect(json).to.deep.equal({
type: 'document',
content: [
{
type: 'paragraph',
},
],
})
})
})
})

View File

@@ -9,6 +9,20 @@ context('/api/extensions/hard-break', () => {
})
})
it('should parse hard breaks correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p>Example<br>Text</p>')
expect(editor.getHTML()).to.eq('<p>Example<br>Text</p>')
})
})
it('should parse hard breaks with self-closing tag correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p>Example<br />Text</p>')
expect(editor.getHTML()).to.eq('<p>Example<br>Text</p>')
})
})
it('the button should add a line break', () => {
cy.get('.ProseMirror br')
.should('not.exist')
@@ -20,7 +34,7 @@ context('/api/extensions/hard-break', () => {
.should('exist')
})
it('the default keyboard shortcut should add a line break', () => {
it.skip('the default keyboard shortcut should add a line break', () => {
cy.get('.ProseMirror br')
.should('not.exist')

View File

@@ -10,6 +10,28 @@ context('/api/extensions/heading', () => {
})
})
const headings = [
'<h1>Example Text</h1>',
'<h2>Example Text</h2>',
'<h3>Example Text</h3>',
]
headings.forEach(html => {
it(`should parse headings correctly (${html})`, () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent(html)
expect(editor.getHTML()).to.eq(html)
})
})
})
it('should omit disabled heading levels', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<h4>Example Text</h4>')
expect(editor.getHTML()).to.eq('<p>Example Text</p>')
})
})
it('the button should make the selected line a h1', () => {
cy.get('.ProseMirror h1')
.should('not.exist')

View File

@@ -9,6 +9,20 @@ context('/api/extensions/horizontal-rule', () => {
})
})
it('should parse horizontal rules correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p>Example Text</p><hr>')
expect(editor.getHTML()).to.eq('<p>Example Text</p><hr>')
})
})
it('should parse horizontal rules with self-closing tag correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p>Example Text</p><hr />')
expect(editor.getHTML()).to.eq('<p>Example Text</p><hr>')
})
})
it('the button should add a horizontal rule', () => {
cy.get('.ProseMirror hr')
.should('not.exist')

View File

@@ -0,0 +1,45 @@
<template>
<div v-if="editor">
<editor-content :editor="editor" />
</div>
</template>
<script>
import { Editor } from '@tiptap/core'
import { EditorContent } from '@tiptap/vue'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import Image from '@tiptap/extension-image'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document(),
Paragraph(),
Text(),
Image(),
],
content: `
<p>This is basic example of implementing images. Try to drop new images here. Reordering also works.</p>
<img src="https://66.media.tumblr.com/dcd3d24b79d78a3ee0f9192246e727f1/tumblr_o00xgqMhPM1qak053o1_400.gif" />
`,
})
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>

View File

@@ -10,6 +10,27 @@ context('/api/extensions/italic', () => {
})
})
it('i tags should be transformed to em tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><i>Example Text</i></p>')
expect(editor.getHTML()).to.eq('<p><em>Example Text</em></p>')
})
})
it('i tags with normal font style should be omitted', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><i style="font-style: normal">Example Text</i></p>')
expect(editor.getHTML()).to.eq('<p>Example Text</p>')
})
})
it('generic tags with italic style should be transformed to strong tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><span style="font-style: italic">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><em>Example Text</em></p>')
})
})
it('the button should make the selected text italic', () => {
cy.get('.demo__preview button:first')
.click()

View File

@@ -10,6 +10,27 @@ context('/api/extensions/link', () => {
})
})
it('should parse a tags correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><a href="#">Example Text</a></p>')
expect(editor.getHTML()).to.eq('<p><a href="#" target="_blank" rel="noopener noreferrer nofollow">Example Text</a></p>')
})
})
it('should parse a tags with target attribute correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><a href="#" target="_self">Example Text</a></p>')
expect(editor.getHTML()).to.eq('<p><a href="#" target="_self" rel="noopener noreferrer nofollow">Example Text</a></p>')
})
})
it('should parse a tags with rel attribute correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><a href="#" rel="follow">Example Text</a></p>')
expect(editor.getHTML()).to.eq('<p><a href="#" target="_blank" rel="noopener noreferrer nofollow">Example Text</a></p>')
})
})
it('the button should add a link to the selected text', () => {
cy.window().then(win => {
cy.stub(win, 'prompt').returns('https://tiptap.dev')

View File

@@ -10,6 +10,20 @@ context('/api/extensions/ordered-list', () => {
})
})
it('should parse ordered lists correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<ol><li><p>Example Text</p></li></ol>')
expect(editor.getHTML()).to.eq('<ol><li><p>Example Text</p></li></ol>')
})
})
it('should parse ordered lists without paragraphs correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<ol><li>Example Text</li></ol>')
expect(editor.getHTML()).to.eq('<ol><li><p>Example Text</p></li></ol>')
})
})
it('the button should make the selected line a ordered list item', () => {
cy.get('.ProseMirror ol')
.should('not.exist')

View File

@@ -38,10 +38,15 @@ export default {
ListItem(),
],
content: `
<ul>
<ol>
<li>A list item</li>
<li>And another one</li>
</ul>
</ol>
<ol start="5">
<li>This item starts at 5</li>
<li>And another one</li>
</ol>
`,
})
},

View File

@@ -9,6 +9,19 @@ context('/api/extensions/paragraph', () => {
})
})
it('should parse paragraphs correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p>Example Text</p>')
expect(editor.getHTML()).to.eq('<p>Example Text</p>')
editor.setContent('<p><x-unknown>Example Text</x-unknown></p>')
expect(editor.getHTML()).to.eq('<p>Example Text</p>')
editor.setContent('<p style="display: block;">Example Text</p>')
expect(editor.getHTML()).to.eq('<p>Example Text</p>')
})
})
it('text should be wrapped in a paragraph by default', () => {
cy.get('.ProseMirror')
.type('Example Text')

View File

@@ -10,6 +10,34 @@ context('/api/extensions/strike', () => {
})
})
it('should parse s tags correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><s>Example Text</s></p>')
expect(editor.getHTML()).to.eq('<p><s>Example Text</s></p>')
})
})
it('should transform del tags to s tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><del>Example Text</del></p>')
expect(editor.getHTML()).to.eq('<p><s>Example Text</s></p>')
})
})
it('should transform strike tags to s tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><strike>Example Text</strike></p>')
expect(editor.getHTML()).to.eq('<p><s>Example Text</s></p>')
})
})
it('should transform any tag with text decoration line through to s tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><span style="text-decoration: line-through">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><s>Example Text</s></p>')
})
})
it('the button should strike the selected text', () => {
cy.get('.demo__preview button:first')
.click()
@@ -51,7 +79,7 @@ context('/api/extensions/strike', () => {
it('should make a striked text from the markdown shortcut', () => {
cy.get('.ProseMirror')
.type('~Strike~')
.type('~~Strike~~')
.find('s')
.should('contain', 'Strike')
})

View File

@@ -0,0 +1,18 @@
context('/api/extensions/text', () => {
before(() => {
cy.visit('/api/extensions/text')
})
beforeEach(() => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.clearContent()
})
})
it('text should be wrapped in a paragraph by default', () => {
cy.get('.ProseMirror')
.type('Example Text')
.find('p')
.should('contain', 'Example Text')
})
})

View File

@@ -0,0 +1,57 @@
<template>
<div v-if="editor">
<button @click="editor.chain().focus().textAlign('left').run()">
left
</button>
<button @click="editor.chain().focus().textAlign('center').run()">
center
</button>
<button @click="editor.chain().focus().textAlign('right').run()">
right
</button>
<editor-content :editor="editor" />
</div>
</template>
<script>
import { Editor } from '@tiptap/core'
import { EditorContent } from '@tiptap/vue'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Heading from '@tiptap/extension-heading'
import Text from '@tiptap/extension-text'
import TextAlign from '@tiptap/extension-text-align'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document(),
Paragraph(),
Text(),
Heading(),
TextAlign(),
],
content: `
<h2>Heading</h2>
<p style="text-align: center">first paragraph</p>
<p style="text-align: right">second paragraph</p>
`,
})
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>

View File

@@ -10,6 +10,20 @@ context('/api/extensions/underline', () => {
})
})
it('should parse u tags correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><u>Example Text</u></p>')
expect(editor.getHTML()).to.eq('<p><u>Example Text</u></p>')
})
})
it('should transform any tag with text decoration underline to u tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><span style="text-decoration: underline">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><u>Example Text</u></p>')
})
})
it('the button should underline the selected text', () => {
cy.get('.demo__preview button:first')
.click()