This commit is contained in:
Philipp Kühn
2020-09-10 13:50:44 +02:00
13 changed files with 216 additions and 51 deletions

View File

@@ -29,5 +29,17 @@ context('/api/extensions/bold', () => {
cy.get('.ProseMirror').type('{meta}b', {force: true}).type('{meta}b', {force: true}) cy.get('.ProseMirror').type('{meta}b', {force: true}).type('{meta}b', {force: true})
cy.get('.ProseMirror strong').should('not.exist') cy.get('.ProseMirror strong').should('not.exist')
}) })
it('should make a bold text from the default markdown shortcut', () => {
cy.get('.ProseMirror')
.type('**Bold**', {force: true})
.contains('strong', 'Bold')
})
it('should make a bold text from the alternative markdown shortcut', () => {
cy.get('.ProseMirror')
.type('__Bold__', {force: true})
.contains('strong', 'Bold')
})
}) })
}) })

View File

@@ -0,0 +1,40 @@
context('/api/extensions/horizontal-rule', () => {
beforeEach(() => {
cy.visit('/api/extensions/horizontal-rule')
cy.get('.ProseMirror').window().then(window => {
const { editor } = window
editor.setContent('<p>Example Text</p>')
})
})
describe('horizontal-rule', () => {
it('the button should add a horizontal rule', () => {
cy.get('.ProseMirror hr').should('not.exist')
cy.get('.demo__preview button:first').click({ force: true })
cy.get('.ProseMirror hr').should('exist')
})
it('the default markdown shortcut should add a horizontal rule', () => {
cy.get('.ProseMirror').window().then(window => {
const { editor } = window
editor.clearContent()
cy.get('.ProseMirror hr').should('not.exist')
cy.get('.ProseMirror').type('---', {force: true})
cy.get('.ProseMirror hr').should('exist')
})
})
it('the alternative markdown shortcut should add a horizontal rule', () => {
cy.get('.ProseMirror').window().then(window => {
const { editor } = window
editor.clearContent()
cy.get('.ProseMirror hr').should('not.exist')
cy.get('.ProseMirror').type('___ ', {force: true})
cy.get('.ProseMirror hr').should('exist')
})
})
})
})

View File

@@ -0,0 +1,54 @@
<template>
<div v-if="editor">
<button @click="editor.focus().horizontalRule()">
horizontalRule
</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 Text from '@tiptap/extension-text'
import HorizontalRule from '@tiptap/extension-horizontal-rule'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document(),
Paragraph(),
Text(),
HorizontalRule(),
],
content: `
<p>This is a paragraph.</p>
<hr>
<p>And this is another paragraph.</p>
<hr>
<p>But between those paragraphs are horizontal rules.</p>
`,
})
window.editor = this.editor
},
beforeDestroy() {
this.editor.destroy()
}
}
</script>

View File

@@ -32,7 +32,7 @@ context('/api/extensions/strike', () => {
it('should make a striked text from the markdown shortcut', () => { it('should make a striked text from the markdown shortcut', () => {
cy.get('.ProseMirror') cy.get('.ProseMirror')
.type('~~Strike~~', {force: true}) .type('~Strike~', {force: true})
.contains('s', 'Strike') .contains('s', 'Strike')
}) })
}) })

View File

@@ -0,0 +1,33 @@
context('/api/extensions/underline', () => {
beforeEach(() => {
cy.visit('/api/extensions/underline')
cy.get('.ProseMirror').window().then(window => {
const { editor } = window
editor.setContent('<p>Example Text</p>')
editor.focus().selectAll()
})
})
describe('bold', () => {
it('the button should underline the selected text', () => {
cy.get('.demo__preview button:first').click({ force: true })
cy.get('.ProseMirror').contains('u', 'Example Text')
})
it('the button should toggle the selected text underline', () => {
cy.get('.demo__preview button:first').dblclick({ force: true })
cy.get('.ProseMirror u').should('not.exist')
})
it('the keyboard shortcut should underline the selected text', () => {
cy.get('.ProseMirror').type('{meta}u', {force: true})
cy.get('.ProseMirror').contains('u', 'Example Text')
})
it('the keyboard shortcut should toggle the selected text underline', () => {
cy.get('.ProseMirror').type('{meta}u', {force: true}).type('{meta}u', {force: true})
cy.get('.ProseMirror u').should('not.exist')
})
})
})

View File

@@ -0,0 +1,52 @@
<template>
<div v-if="editor">
<button @click="editor.focus().underline()" :class="{ 'is-active': editor.isActive('underline') }">
underline
</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 Text from '@tiptap/extension-text'
import Underline from '@tiptap/extension-underline'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document(),
Paragraph(),
Text(),
Underline(),
],
content: `
<p>There is no underline here.</p>
<p><u>This is underlined though.</u></p>
<p style="text-decoration: underline">And this as well.</p>
`,
})
window.editor = this.editor
},
beforeDestroy() {
this.editor.destroy()
}
}
</script>

View File

@@ -1,7 +1,7 @@
# Blockquote # Blockquote
The Blockquote extension enables you to use the `<blockquote>` HTML tag in the editor. This is great you might have guessed to use quotes in the editor. The Blockquote extension enables you to use the `<blockquote>` HTML tag in the editor. This is great you might have guessed to use quotes in the editor.
Type `> ` on the beginning of a new line and it will be magically transformed to a blockquote. Type `> ` at the beginning of a new line and it will be magically transformed to a blockquote.
## Options ## Options
| Option | Type | Default | Description | | Option | Type | Default | Description |

View File

@@ -1,5 +1,5 @@
# Bold # Bold
This extension is used to render text in **bold**. If you pass `<strong>`, `<b>` tags, or text with inline `style` attributes setting the `font-weight` CSS rule in the editors initial content, they all will be rendered accordingly. Use this extension to render text in **bold**. If you pass `<strong>`, `<b>` tags, or text with inline `style` attributes setting the `font-weight` CSS rule in the editors initial content, they all will be rendered accordingly.
Type `**two asterisks**` or `__two underlines__` and the it will be magically transformed to **bold** text while you type. Type `**two asterisks**` or `__two underlines__` and the it will be magically transformed to **bold** text while you type.

View File

@@ -1,5 +1,7 @@
# HorizontalRule # HorizontalRule
Enables you to use the `<hr>` HTML tag in the editor. Use this extension to render a `<hr>` HTML tag. If you pass `<hr>` in the editors initial content, itll be rendered accordingly.
Type `---` (three dashes) or `___ ` (three underscores and a space) at the beginning of a new line and it will be magically transformed to a horizontal rule.
## Options ## Options
| Option | Type | Default | Description | | Option | Type | Default | Description |
@@ -9,11 +11,17 @@ Enables you to use the `<hr>` HTML tag in the editor.
## Commands ## Commands
| Command | Options | Description | | Command | Options | Description |
| --------------- | ------- | ------------------------- | | --------------- | ------- | ------------------------- |
| horizontal_rule | — | Create a horizontal rule. | | horizontalRule | — | Create a horizontal rule. |
## Keyboard shortcuts ## Keyboard shortcuts
*None* *None*
## Source Code
[packages/extension-horizontal-rule/](https://github.com/ueberdosis/tiptap-next/blob/main/packages/extension-horizontal-rule/)
## Usage
<demo name="Extensions/HorizontalRule" highlight="3-5,17,36" />
## Usage ## Usage
```markup ```markup
<template> <template>

View File

@@ -1,5 +1,5 @@
# Italic # Italic
This extension is used to render text in *italic*. If you pass `<em>`, `<i>` tags, or text with inline `style` attributes setting `font-style: italic` in the editors initial content, they all will be rendered accordingly. Use this extension to render text in *italic*. If you pass `<em>`, `<i>` tags, or text with inline `style` attributes setting `font-style: italic` in the editors initial content, they all will be rendered accordingly.
::: warning Restrictions ::: warning Restrictions
The extension will generate the corresponding `<em>` HTML tags when reading contents of the `Editor` instance. All text marked italic, regardless of the method will be normalized to `<em>` HTML tags. The extension will generate the corresponding `<em>` HTML tags when reading contents of the `Editor` instance. All text marked italic, regardless of the method will be normalized to `<em>` HTML tags.

View File

@@ -1,7 +1,7 @@
# Strike # Strike
This extension is used to render ~~striked text~~. If you pass `<s>`, `<del>`, `<strike>` tags, or text with inline `style` attributes setting `text-decoration: line-through` in the editors initial content, they all will be rendered accordingly. Use this extension to render ~~striked text~~. If you pass `<s>`, `<del>`, `<strike>` tags, or text with inline `style` attributes setting `text-decoration: line-through` in the editors initial content, they all will be rendered accordingly.
Type `~~two tildes~~` and the it will be magically ~~striked through~~ while you type. Type `~text between tildes~` and it will be magically ~~striked through~~ while you type.
::: warning Restrictions ::: warning Restrictions
The extension will generate the corresponding `<s>` HTML tags when reading contents of the `Editor` instance. All text striked through, regardless of the method will be normalized to `<s>` HTML tags. The extension will generate the corresponding `<s>` HTML tags when reading contents of the `Editor` instance. All text striked through, regardless of the method will be normalized to `<s>` HTML tags.

View File

@@ -1,5 +1,9 @@
# Underline # Underline
Enables you to use the `<u>` HTML tag in the editor. Use this extension to render text <u>underlined</u>. If you pass `<u>` tags, or text with inline `style` attributes setting `text-decoration: underline` in the editors initial content, they all will be rendered accordingly.
::: warning Restrictions
The extension will generate the corresponding `<u>` HTML tags when reading contents of the `Editor` instance. All text marked underlined, regardless of the method will be normalized to `<u>` HTML tags.
:::
## Options ## Options
| Option | Type | Default | Description | | Option | Type | Default | Description |
@@ -15,45 +19,8 @@ Enables you to use the `<u>` HTML tag in the editor.
* Windows & Linux: `Control` + `U` * Windows & Linux: `Control` + `U`
* macOS: `Command` + `U` * macOS: `Command` + `U`
## Source Code
[packages/extension-underline/](https://github.com/ueberdosis/tiptap-next/blob/main/packages/extension-underline/)
## Usage ## Usage
```markup <demo name="Extensions/Underline" highlight="3-5,17,36" />
<template>
<div>
<editor-menu-bar :editor="editor" v-slot="{ commands, isActive }">
<button type="button" :class="{ 'is-active': isActive.underline() }" @click="commands.underline">
Underline
</button>
</editor-menu-bar>
<editor-content :editor="editor" />
</div>
</template>
<script>
import { Editor, EditorContent, EditorMenuBar } from 'tiptap'
import { Underline } from 'tiptap-extensions'
export default {
components: {
EditorMenuBar,
EditorContent,
},
data() {
return {
editor: new Editor({
extensions: [
Underline(),
],
content: `
<p><u>This is underlined.</u></p>
<p style="text-decoration: underline">This as well.</p>
`,
}),
}
},
beforeDestroy() {
this.editor.destroy()
}
}
</script>
```

View File

@@ -184,7 +184,6 @@
# draft: true # draft: true
- title: Underline - title: Underline
link: /api/extensions/underline link: /api/extensions/underline
draft: true
- title: Commands - title: Commands
link: /api/commands link: /api/commands
draft: true draft: true