add code extension demo with tests
This commit is contained in:
@@ -13,9 +13,6 @@ context('/api/extensions/bold', () => {
|
||||
it('should make the selected text bold', () => {
|
||||
cy.get('.demo__preview button:first').click({ force: true })
|
||||
cy.get('.ProseMirror').contains('strong', 'Example Text')
|
||||
|
||||
cy.get('.demo__preview button:first').click({ force: true })
|
||||
cy.get('.ProseMirror strong').should('not.exist')
|
||||
})
|
||||
|
||||
it('should toggle the selected text bold', () => {
|
||||
|
||||
23
docs/src/demos/Extensions/Code/index.spec.js
Normal file
23
docs/src/demos/Extensions/Code/index.spec.js
Normal file
@@ -0,0 +1,23 @@
|
||||
context('/api/extensions/code', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('/api/extensions/code')
|
||||
|
||||
cy.get('.ProseMirror').window().then(window => {
|
||||
const { editor } = window
|
||||
editor.setContent('<p>Example Text</p>')
|
||||
editor.focus().selectAll()
|
||||
})
|
||||
})
|
||||
|
||||
describe('code', () => {
|
||||
it('should mark the selected text as inline code', () => {
|
||||
cy.get('.demo__preview button:first').click({ force: true })
|
||||
cy.get('.ProseMirror').contains('code', 'Example Text')
|
||||
})
|
||||
|
||||
it('should toggle the selected text as inline code', () => {
|
||||
cy.get('.demo__preview button:first').dblclick({ force: true })
|
||||
cy.get('.ProseMirror code').should('not.exist')
|
||||
})
|
||||
})
|
||||
})
|
||||
51
docs/src/demos/Extensions/Code/index.vue
Normal file
51
docs/src/demos/Extensions/Code/index.vue
Normal file
@@ -0,0 +1,51 @@
|
||||
<template>
|
||||
<div v-if="editor">
|
||||
<button @click="editor.focus().code()" :class="{ 'is-active': editor.isActive('code') }">
|
||||
code
|
||||
</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 Code from '@tiptap/extension-code'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
EditorContent,
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
editor: null,
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.editor = new Editor({
|
||||
extensions: [
|
||||
new Document(),
|
||||
new Paragraph(),
|
||||
new Text(),
|
||||
new Code(),
|
||||
],
|
||||
content: `
|
||||
<p>This isn’t code.</p>
|
||||
<p><code>This is code.</code></p>
|
||||
`,
|
||||
})
|
||||
|
||||
window.editor = this.editor
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
this.editor.destroy()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -13,9 +13,6 @@ context('/api/extensions/italic', () => {
|
||||
it('should make the selected text italic', () => {
|
||||
cy.get('.demo__preview button:first').click({ force: true })
|
||||
cy.get('.ProseMirror').contains('em', 'Example Text')
|
||||
|
||||
cy.get('.demo__preview button:first').click({ force: true })
|
||||
cy.get('.ProseMirror em').should('not.exist')
|
||||
})
|
||||
|
||||
it('should toggle the selected text italic', () => {
|
||||
|
||||
@@ -1,55 +1,19 @@
|
||||
# Code
|
||||
The Code extensions enables you to use the `<code>` HTML tag in the editor.
|
||||
The Code extensions enables you to use the `<code>` HTML tag in the editor. If you paste in text with `<code>` tags it will rendered accordingly.
|
||||
|
||||
## Options
|
||||
*None*
|
||||
|
||||
## Commands
|
||||
| Command | Options | Description |
|
||||
| ------ | ---- | ---------------- |
|
||||
| code | — | Mark text as code. |
|
||||
| ------- | ------- | ----------- |
|
||||
| code | — | Mark text as inline code. |
|
||||
|
||||
## Keybindings
|
||||
* `Alt` + `
|
||||
|
||||
## Source Code
|
||||
[packages/extension-code/](https://github.com/ueberdosis/tiptap-next/blob/main/packages/extension-code/)
|
||||
|
||||
## Usage
|
||||
```markup
|
||||
<template>
|
||||
<div>
|
||||
<editor-menu-bar :editor="editor" v-slot="{ commands, isActive }">
|
||||
<button type="button" :class="{ 'is-active': isActive.code() }" @click="commands.code">
|
||||
Code
|
||||
</button>
|
||||
</editor-menu-bar>
|
||||
|
||||
<editor-content :editor="editor" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { Editor, EditorContent, EditorMenuBar } from 'tiptap'
|
||||
import { Code } from 'tiptap-extensions'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
EditorMenuBar,
|
||||
EditorContent,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
editor: new Editor({
|
||||
extensions: [
|
||||
new Code(),
|
||||
],
|
||||
content: `
|
||||
<p>This is some <code>inline code.</code></p>
|
||||
`,
|
||||
}),
|
||||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.editor.destroy()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
```
|
||||
<demo name="Extensions/Code" highlight="3-5,17,36" />
|
||||
@@ -10,7 +10,7 @@ The extension will generate the corresponding `<em>` HTML tags when reading cont
|
||||
|
||||
## Commands
|
||||
| Command | Options | Description |
|
||||
| ------ | ---- | ---------------- |
|
||||
| ------- | ------- | ----------- |
|
||||
| italic | — | Mark text italic. |
|
||||
|
||||
## Keybindings
|
||||
|
||||
@@ -117,7 +117,6 @@
|
||||
draft: true
|
||||
- title: Code
|
||||
link: /api/extensions/code
|
||||
draft: true
|
||||
- title: CodeBlock
|
||||
link: /api/extensions/code-block
|
||||
draft: true
|
||||
|
||||
Reference in New Issue
Block a user