2020-08-19 03:39:41 +08:00
|
|
|
|
# Heading
|
2020-08-20 21:44:08 +08:00
|
|
|
|
Enables you to use headline HTML tags in the editor.
|
2020-08-19 03:39:41 +08:00
|
|
|
|
|
2020-08-20 21:33:16 +08:00
|
|
|
|
## Options
|
2020-09-10 16:21:24 +08:00
|
|
|
|
| Option | Type | Default | Description |
|
|
|
|
|
| ------ | ------ | ------------------ | -------------------------------------------- |
|
|
|
|
|
| class | string | – | Add a custom class to the rendered HTML tag. |
|
|
|
|
|
| levels | Array | [1, 2, 3, 4, 5, 6] | Specifies which headlines are supported. |
|
2020-08-19 03:39:41 +08:00
|
|
|
|
|
2020-08-20 21:33:16 +08:00
|
|
|
|
## Commands
|
2020-09-10 16:21:24 +08:00
|
|
|
|
| Command | Options | Description |
|
|
|
|
|
| ------- | ------- | ----------------------- |
|
|
|
|
|
| heading | level | Creates a heading node. |
|
2020-08-19 03:39:41 +08:00
|
|
|
|
|
2020-09-10 17:24:33 +08:00
|
|
|
|
## Keyboard shortcuts
|
2020-08-19 03:39:41 +08:00
|
|
|
|
* `Control` + `Shift` + `1` → H1
|
|
|
|
|
* `Control` + `Shift` + `2` → H2
|
|
|
|
|
* `Control` + `Shift` + `3` → H3
|
|
|
|
|
* `Control` + `Shift` + `4` → H4
|
|
|
|
|
* `Control` + `Shift` + `5` → H5
|
|
|
|
|
* `Control` + `Shift` + `6` → H6
|
|
|
|
|
|
2020-08-20 21:33:16 +08:00
|
|
|
|
## Usage
|
2020-08-19 03:39:41 +08:00
|
|
|
|
```markup
|
|
|
|
|
<template>
|
|
|
|
|
<div>
|
|
|
|
|
<editor-menu-bar :editor="editor" v-slot="{ commands, isActive }">
|
|
|
|
|
<div>
|
|
|
|
|
<button type="button" :class="{ 'is-active': isActive.heading({ level: 1 }) }" @click="commands.heading({ level: 1})">
|
|
|
|
|
H1
|
|
|
|
|
</button>
|
|
|
|
|
<button type="button" :class="{ 'is-active': isActive.heading({ level: 2 }) }" @click="commands.heading({ level: 2 })">
|
|
|
|
|
H2
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</editor-menu-bar>
|
|
|
|
|
|
|
|
|
|
<editor-content :editor="editor" />
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import { Editor, EditorContent, EditorMenuBar } from 'tiptap'
|
|
|
|
|
import { Heading } from 'tiptap-extensions'
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
components: {
|
|
|
|
|
EditorMenuBar,
|
|
|
|
|
EditorContent,
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
editor: new Editor({
|
|
|
|
|
extensions: [
|
2020-09-09 16:58:10 +08:00
|
|
|
|
Heading({
|
2020-08-19 03:39:41 +08:00
|
|
|
|
levels: [1, 2],
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
content: `
|
|
|
|
|
<h1>This is a headline level 1</h1>
|
|
|
|
|
<h2>This is a headline level 2</h2>
|
|
|
|
|
<h3>This headline will be converted to a paragraph, because it's not defined in the levels option.</h3>
|
|
|
|
|
`,
|
|
|
|
|
}),
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
beforeDestroy() {
|
|
|
|
|
this.editor.destroy()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|