mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-24 17:47:50 +08:00
74 lines
2.5 KiB
Markdown
74 lines
2.5 KiB
Markdown
---
|
|
description: Structure the content with headings (comes with 6 different levels or less).
|
|
icon: h-1
|
|
---
|
|
|
|
# Heading
|
|
[![Version](https://img.shields.io/npm/v/@tiptap/extension-heading.svg?label=version)](https://www.npmjs.com/package/@tiptap/extension-heading)
|
|
[![Downloads](https://img.shields.io/npm/dm/@tiptap/extension-heading.svg)](https://npmcharts.com/compare/@tiptap/extension-heading?minimal=true)
|
|
|
|
The Heading extension adds support for headings of different levels. Headings are rendered with `<h1>`, `<h2>`, `<h3>`, `<h4>`, `<h5>` or `<h6>` HTML tags. By default all six heading levels (or styles) are enabled, but you can pass an array to only allow a few levels. Check the usage example to see how this is done.
|
|
|
|
Type <code># </code> at the beginning of a new line and it will magically transform to a heading, same for <code>## </code>, <code>### </code>, <code>#### </code>, <code>##### </code> and <code>###### </code>.
|
|
|
|
## Installation
|
|
```bash
|
|
npm install @tiptap/extension-heading
|
|
```
|
|
|
|
## Settings
|
|
|
|
### HTMLAttributes
|
|
Custom HTML attributes that should be added to the rendered HTML tag.
|
|
|
|
```js
|
|
Heading.configure({
|
|
HTMLAttributes: {
|
|
class: 'my-custom-class',
|
|
},
|
|
})
|
|
```
|
|
|
|
### levels
|
|
Specifies which heading levels are supported.
|
|
|
|
Default: `[1, 2, 3, 4, 5, 6]`
|
|
|
|
```js
|
|
Heading.configure({
|
|
levels: [1, 2],
|
|
})
|
|
```
|
|
|
|
## Commands
|
|
|
|
### setHeading()
|
|
Creates a heading node with the specified level.
|
|
|
|
```js
|
|
editor.commands.setHeading({ level: 1 })
|
|
```
|
|
|
|
### toggleHeading()
|
|
Toggles a heading node with the specified level.
|
|
|
|
```js
|
|
editor.commands.toggleHeading({ level: 1 })
|
|
```
|
|
|
|
## Keyboard shortcuts
|
|
| Command | Windows/Linux | macOS |
|
|
| --------------------------- | ----------------------------- | ------------------------- |
|
|
| toggleHeading({ level: 1 }) | `Control` `Alt` `1` | `Cmd` `Alt` `1` |
|
|
| toggleHeading({ level: 2 }) | `Control` `Alt` `2` | `Cmd` `Alt` `2` |
|
|
| toggleHeading({ level: 3 }) | `Control` `Alt` `3` | `Cmd` `Alt` `3` |
|
|
| toggleHeading({ level: 4 }) | `Control` `Alt` `4` | `Cmd` `Alt` `4` |
|
|
| toggleHeading({ level: 5 }) | `Control` `Alt` `5` | `Cmd` `Alt` `5` |
|
|
| toggleHeading({ level: 6 }) | `Control` `Alt` `6` | `Cmd` `Alt` `6` |
|
|
|
|
## Source code
|
|
[packages/extension-heading/](https://github.com/ueberdosis/tiptap/blob/main/packages/extension-heading/)
|
|
|
|
## Usage
|
|
https://embed.tiptap.dev/preview/Nodes/Heading
|