tiptap Paragraph 扩展,把数据渲染成 html 的 p 标签,这很重要是文档的基础组成部分。
npm install @tiptap/extension-paragraph
HTMLAttributes 自定义标签对应的HTML属性。
Paragraph.configure({
HTMLAttributes: {
class: 'custom-class',
},
})
setParagraph 将选中节点转换成段落。
editor.commands.setParagraph()
Vue 例子
React 例子
<template>
<div v-if="editor">
<editor-content :editor="editor" />
</div>
</template>
<script>
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import { Editor, EditorContent } from '@tiptap/vue-3'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document,
Paragraph,
Text,
],
content: `
<p>The Paragraph extension is not required, but it’s very likely you want to use it. It’s needed to write paragraphs of text. </p>
`,
})
},
beforeUnmount() {
this.editor.destroy()
},
}
</script>
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import { EditorContent, useEditor } from '@tiptap/react'
import React from 'react'
export default () => {
const editor = useEditor({
extensions: [Document, Paragraph, Text],
content: `
<p>The Paragraph extension is not required, but it’s very likely you want to use it. It’s needed to write paragraphs of text. </p>
`,
})
if (!editor) {
return null
}
return <EditorContent editor={editor} />
}