2021-10-14 06:13:50 +08:00
|
|
|
|
---
|
|
|
|
|
description: Limit the number of characters in your editor, or at least count them.
|
2021-10-16 04:48:57 +08:00
|
|
|
|
icon: calculator-line
|
2021-10-14 06:13:50 +08:00
|
|
|
|
---
|
|
|
|
|
|
2021-01-26 06:40:15 +08:00
|
|
|
|
# CharacterCount
|
|
|
|
|
[![Version](https://img.shields.io/npm/v/@tiptap/extension-character-count.svg?label=version)](https://www.npmjs.com/package/@tiptap/extension-character-count)
|
|
|
|
|
[![Downloads](https://img.shields.io/npm/dm/@tiptap/extension-character-count.svg)](https://npmcharts.com/compare/@tiptap/extension-character-count?minimal=true)
|
|
|
|
|
|
|
|
|
|
The `CharacterCount` extension limits the number of allowed character to a specific length. That’s it, that’s all.
|
|
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
```bash
|
|
|
|
|
npm install @tiptap/extension-character-count
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Settings
|
2021-10-02 07:20:09 +08:00
|
|
|
|
|
|
|
|
|
### limit
|
|
|
|
|
|
2021-12-09 04:26:30 +08:00
|
|
|
|
The maximum number of characters that should be allowed.
|
2021-10-02 07:20:09 +08:00
|
|
|
|
|
2021-12-15 02:26:13 +08:00
|
|
|
|
Default: `null`
|
2021-10-02 07:20:09 +08:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
CharacterCount.configure({
|
|
|
|
|
limit: 240,
|
|
|
|
|
})
|
|
|
|
|
```
|
2021-01-26 06:40:15 +08:00
|
|
|
|
|
2021-12-09 04:26:30 +08:00
|
|
|
|
### mode
|
2021-01-26 06:40:15 +08:00
|
|
|
|
|
2021-12-09 04:26:30 +08:00
|
|
|
|
The mode by which the size is calculated.
|
2021-03-31 03:17:10 +08:00
|
|
|
|
|
2021-12-09 04:26:30 +08:00
|
|
|
|
Default: `'textSize'`
|
2021-03-31 03:17:10 +08:00
|
|
|
|
|
|
|
|
|
```js
|
2021-12-09 04:26:30 +08:00
|
|
|
|
CharacterCount.configure({
|
|
|
|
|
mode: 'nodeSize',
|
2021-03-31 03:17:10 +08:00
|
|
|
|
})
|
|
|
|
|
```
|
2021-12-09 04:26:30 +08:00
|
|
|
|
|
|
|
|
|
## Storage
|
|
|
|
|
|
|
|
|
|
### characters()
|
|
|
|
|
Get the number of characters for the current document.
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
editor.storage.characterCount.characters()
|
|
|
|
|
|
|
|
|
|
// Get the size of a specific node.
|
|
|
|
|
editor.storage.characterCount.characters({ node: someCustomNode })
|
|
|
|
|
|
|
|
|
|
// Overwrite the default `mode`.
|
|
|
|
|
editor.storage.characterCount.characters({ mode: 'nodeSize' })
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### words()
|
|
|
|
|
Get the number of words for the current document.
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
editor.storage.characterCount.words()
|
|
|
|
|
|
|
|
|
|
// Get the number of words for a specific node.
|
|
|
|
|
editor.storage.characterCount.words({ node: someCustomNode })
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Source code
|
|
|
|
|
[packages/extension-character-count/](https://github.com/ueberdosis/tiptap/blob/main/packages/extension-character-count/)
|
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
https://embed.tiptap.dev/preview/Extensions/CharacterCount
|