add an interactive demo and tests to the underline extension
This commit is contained in:
33
docs/src/demos/Extensions/Underline/index.spec.js
Normal file
33
docs/src/demos/Extensions/Underline/index.spec.js
Normal 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')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
52
docs/src/demos/Extensions/Underline/index.vue
Normal file
52
docs/src/demos/Extensions/Underline/index.vue
Normal 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>
|
||||||
@@ -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 editor’s 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 editor’s 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.
|
||||||
|
|
||||||
|
|||||||
@@ -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 editor’s 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 editor’s 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.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# 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 editor’s 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 editor’s initial content, they all will be rendered accordingly.
|
||||||
|
|
||||||
Type `~text between tildes~` and it will be magically ~~striked through~~ while you type.
|
Type `~text between tildes~` and it will be magically ~~striked through~~ while you type.
|
||||||
|
|
||||||
|
|||||||
@@ -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 editor’s 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>
|
|
||||||
```
|
|
||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user