tiptap 中文文档

tiptap Paragraph 段落节点

tiptap Paragraph 扩展,把数据渲染成 htmlp 标签,这很重要是文档的基础组成部分。

Install 安装

npm install @tiptap/extension-paragraph

Settings 配置

HTMLAttributes 自定义标签对应的HTML属性。

Paragraph.configure({
  HTMLAttributes: {
    class: 'custom-class',
  },
})

Commands 命令

setParagraph 将选中节点转换成段落。

editor.commands.setParagraph()

源代码

paragraph 源代码

Paragraph 例子

  • 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} />
}
Catalog
快速入门 Guide 向导 API 列表 tiptap 方法 tiptap 属性 titap 配置 commands 命令 nodes 节点 Blockquote 引用扩展 BulletList 无序序列扩展 CodeBlock 代码块扩展 CodeBlockLowlight 代码高亮 Document 节点 HardBreak 换行节点 Heading 标题节点 HorizontalRule 横线节点 Image 图片扩展 ListItem 节点 Mention 提及节点 OrderedList 有序列节点 Paragraph 段落节点 Table 表格扩展 TaskList 任务列表 TaskItem 任务列表项 Text 节点 marks 标记 extensions 扩展