add export html or json example

This commit is contained in:
Hans Pagel
2020-08-20 17:53:28 +02:00
parent 915834a799
commit e2642526a0
3 changed files with 113 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
context('export-html-or-json', () => {
beforeEach(() => {
cy.visit('/examples/export-html-or-json')
})
})

View File

@@ -0,0 +1,96 @@
<template>
<div>
<editor-content :editor="editor" />
<div class="actions">
<button class="button" @click="clearContent">
Clear Content
</button>
<button class="button" @click="setContent">
Set Content
</button>
</div>
<div class="export">
<h3>JSON</h3>
<pre><code v-html="json"></code></pre>
<h3>HTML</h3>
<pre><code>{{ html }}</code></pre>
</div>
</div>
</template>
<script>
import { Editor, EditorContent, defaultExtensions } from '@tiptap/vue-starter-kit'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
json: null,
html: null,
}
},
mounted() {
this.editor = new Editor({
content: `
<h2>
Export HTML or JSON
</h2>
<p>
You are able to export your data as <code>HTML</code> or <code>JSON</code>.
</p>
`,
extensions: defaultExtensions(),
})
this.json = this.editor.json()
this.html = this.editor.html()
this.editor.on('update', () => {
this.json = this.editor.json()
this.html = this.editor.html()
})
window.editor = this.editor
},
methods: {
clearContent() {
this.editor.clearContent(true)
this.editor.focus()
},
setContent() {
// you can pass a json document
this.editor.setContent({
type: 'document',
content: [{
type: 'paragraph',
content: [
{
type: 'text',
text: 'This is some inserted text. 👋',
},
],
}],
}, true)
// HTML string is also supported
// this.editor.setContent('<p>This is some inserted text. 👋</p>')
this.editor.focus()
},
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>
<style lang="scss" src="./style.scss">

View File

@@ -0,0 +1,12 @@
.export {
pre {
border-radius: 5px;
font-size: 0.8rem;
color: rgba($colorBlack, 0.8);
}
code {
display: block;
white-space: pre-wrap;
}
}