From 860b6385ad59c84e32467cbd590357e072b41a3e Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Thu, 10 Sep 2020 12:43:40 +0200 Subject: [PATCH] add an interactive demo and tests to the underline extension --- .../demos/Extensions/Underline/index.spec.js | 33 ++++++++++++ docs/src/demos/Extensions/Underline/index.vue | 52 +++++++++++++++++++ docs/src/docPages/api/extensions/bold.md | 2 +- docs/src/docPages/api/extensions/italic.md | 2 +- docs/src/docPages/api/extensions/strike.md | 2 +- docs/src/docPages/api/extensions/underline.md | 51 ++++-------------- docs/src/links.yaml | 1 - 7 files changed, 97 insertions(+), 46 deletions(-) create mode 100644 docs/src/demos/Extensions/Underline/index.spec.js create mode 100644 docs/src/demos/Extensions/Underline/index.vue diff --git a/docs/src/demos/Extensions/Underline/index.spec.js b/docs/src/demos/Extensions/Underline/index.spec.js new file mode 100644 index 00000000..c1eb33ce --- /dev/null +++ b/docs/src/demos/Extensions/Underline/index.spec.js @@ -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('

Example Text

') + 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') + }) + }) +}) \ No newline at end of file diff --git a/docs/src/demos/Extensions/Underline/index.vue b/docs/src/demos/Extensions/Underline/index.vue new file mode 100644 index 00000000..558d09cc --- /dev/null +++ b/docs/src/demos/Extensions/Underline/index.vue @@ -0,0 +1,52 @@ + + + \ No newline at end of file diff --git a/docs/src/docPages/api/extensions/bold.md b/docs/src/docPages/api/extensions/bold.md index a98ef14e..81f28cf8 100644 --- a/docs/src/docPages/api/extensions/bold.md +++ b/docs/src/docPages/api/extensions/bold.md @@ -1,5 +1,5 @@ # Bold -This extension is used to render text in **bold**. If you pass ``, `` 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 ``, `` 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. diff --git a/docs/src/docPages/api/extensions/italic.md b/docs/src/docPages/api/extensions/italic.md index e566ed22..398f725e 100644 --- a/docs/src/docPages/api/extensions/italic.md +++ b/docs/src/docPages/api/extensions/italic.md @@ -1,5 +1,5 @@ # Italic -This extension is used to render text in *italic*. If you pass ``, `` 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 ``, `` 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 The extension will generate the corresponding `` HTML tags when reading contents of the `Editor` instance. All text marked italic, regardless of the method will be normalized to `` HTML tags. diff --git a/docs/src/docPages/api/extensions/strike.md b/docs/src/docPages/api/extensions/strike.md index 902946d7..36913e65 100644 --- a/docs/src/docPages/api/extensions/strike.md +++ b/docs/src/docPages/api/extensions/strike.md @@ -1,5 +1,5 @@ # Strike -This extension is used to render ~~striked text~~. If you pass ``, ``, `` 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 ``, ``, `` 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. diff --git a/docs/src/docPages/api/extensions/underline.md b/docs/src/docPages/api/extensions/underline.md index 3c4c57d5..ab27c3ce 100644 --- a/docs/src/docPages/api/extensions/underline.md +++ b/docs/src/docPages/api/extensions/underline.md @@ -1,5 +1,9 @@ # Underline -Enables you to use the `` HTML tag in the editor. +Use this extension to render text underlined. If you pass `` 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 `` HTML tags when reading contents of the `Editor` instance. All text marked underlined, regardless of the method will be normalized to `` HTML tags. +::: ## Options | Option | Type | Default | Description | @@ -15,45 +19,8 @@ Enables you to use the `` HTML tag in the editor. * Windows & Linux: `Control` + `U` * macOS: `Command` + `U` +## Source Code +[packages/extension-underline/](https://github.com/ueberdosis/tiptap-next/blob/main/packages/extension-underline/) + ## Usage -```markup - - - -``` \ No newline at end of file + \ No newline at end of file diff --git a/docs/src/links.yaml b/docs/src/links.yaml index 35970fcd..88e76cc3 100644 --- a/docs/src/links.yaml +++ b/docs/src/links.yaml @@ -184,7 +184,6 @@ # draft: true - title: Underline link: /api/extensions/underline - draft: true - title: Commands link: /api/commands draft: true