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
|
|
|
|
|
# with npm
|
|
|
|
|
npm install @tiptap/extension-character-count
|
|
|
|
|
|
|
|
|
|
# with Yarn
|
|
|
|
|
yarn add @tiptap/extension-character-count
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Settings
|
2021-10-02 07:20:09 +08:00
|
|
|
|
|
|
|
|
|
### limit
|
|
|
|
|
|
|
|
|
|
The maximum number of characters that should be allowed. |
|
|
|
|
|
|
|
|
|
|
Default: `0`
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
CharacterCount.configure({
|
|
|
|
|
limit: 240,
|
|
|
|
|
})
|
|
|
|
|
```
|
2021-01-26 06:40:15 +08:00
|
|
|
|
|
|
|
|
|
## Source code
|
2021-04-21 21:31:11 +08:00
|
|
|
|
[packages/extension-character-count/](https://github.com/ueberdosis/tiptap/blob/main/packages/extension-character-count/)
|
2021-01-26 06:40:15 +08:00
|
|
|
|
|
|
|
|
|
## Usage
|
2021-10-19 00:01:47 +08:00
|
|
|
|
https://embed.tiptap.dev/preview/Extensions/CharacterCount
|
2021-03-31 03:17:10 +08:00
|
|
|
|
|
|
|
|
|
## Count words, emojis, letters …
|
|
|
|
|
Want to count words instead? Or emojis? Or the letter *a*? Sure, no problem. You can access the `textContent` directly and count whatever you’re into.
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
new Editor({
|
|
|
|
|
onUpdate({ editor }) {
|
|
|
|
|
const wordCount = editor.state.doc.textContent.split(' ').length
|
|
|
|
|
|
|
|
|
|
console.log(wordCount)
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
```
|