tiptap/docs/api/extensions/character-count.md

73 lines
1.7 KiB
Markdown
Raw Normal View History

---
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-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)
2022-11-08 04:41:00 +08:00
The `CharacterCount` extension limits the number of allowed characters to a specific length and is able to return the number of characters and words. Thats it, thats all.
2021-01-26 06:40:15 +08:00
## Installation
```bash
npm install @tiptap/extension-character-count
```
## Settings
### limit
The maximum number of characters that should be allowed.
Default: `null`
```js
CharacterCount.configure({
limit: 240,
})
```
2021-01-26 06:40:15 +08:00
### mode
2021-01-26 06:40:15 +08:00
The mode by which the size is calculated.
2021-03-31 03:17:10 +08:00
Default: `'textSize'`
2021-03-31 03:17:10 +08:00
```js
CharacterCount.configure({
mode: 'nodeSize',
2021-03-31 03:17:10 +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