---
title: "尾节点扩展"
description: "使用 Tiptap 的尾节点扩展为您的编辑器添加一个尾节点。请在我们的文档中了解更多信息。"
canonical_url: "https://tiptap.zhcndoc.com/editor/extensions/functionality/trailing-node"
---

# 尾节点扩展

使用 Tiptap 的尾节点扩展为您的编辑器添加一个尾节点。请在我们的文档中了解更多信息。

该扩展在编辑器的最后一个块节点后添加一个节点。这对于添加尾节点，如占位符或按钮，可能会很有用。

> **Interactive demo:** [TrailingNode](https://embed.tiptap.dev/preview/Extensions/TrailingNode)

## 安装

```bash
npm install @tiptap/extensions
```

## 用法

```js
import { Editor } from '@tiptap/core'
import { TrailingNode } from '@tiptap/extensions'

new Editor({
  extensions: [TrailingNode],
})
```

## 设置

### node

应在文档末尾插入的节点类型。当未设置此项时，尾节点扩展会向 ProseMirror schema 查询其定义的回退节点（通常是默认块节点），但你可以通过 `node` 选项覆盖此行为。当你定义了自定义文档结构时，这一点尤为重要——请参阅[强制内容结构示例](https://tiptap.zhcndoc.com/examples/advanced/forced-content-structure.md)了解自定义文档如何影响默认回退节点。

默认值：`undefined`

```js
TrailingNode.configure({
  node: 'paragraph',
})
```

### notAfter

在这些节点类型之后不应插入尾节点。

默认值：`['paragraph']`

```js
TrailingNode.configure({
  node: 'paragraph',
  notAfter: ['heading', 'blockquote'],
})
```

## 在事务中跳过尾节点创建

你可以通过在特定事务上设置 `skipTrailingNode` 元标志来跳过该事务的自动尾节点插入。

```ts
editor
  .chain()
  .command(({ tr }) => {
    tr.setMeta('skipTrailingNode', true)

    return true
  })
  .run()
```

当你故意想让某个事务在离开文档时不留下额外的尾节点时，这会很有用。

## 源代码

[packages/extensions/src/trailing-node/](https://github.com/ueberdosis/tiptap/blob/main/packages/extensions/src/trailing-node/)

## 最小安装

```js
import { Editor } from '@tiptap/core'
import { TrailingNode } from '@tiptap/extensions/trailing-node'

new Editor({
  extensions: [TrailingNode],
})
```
