tiptap/docs/api/extensions/character-count.md
2021-10-18 18:01:47 +02:00

53 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
description: Limit the number of characters in your editor, or at least count them.
icon: calculator-line
---
# 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. Thats it, thats all.
## Installation
```bash
# with npm
npm install @tiptap/extension-character-count
# with Yarn
yarn add @tiptap/extension-character-count
```
## Settings
### limit
The maximum number of characters that should be allowed. |
Default: `0`
```js
CharacterCount.configure({
limit: 240,
})
```
## 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
## 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 youre into.
```js
new Editor({
onUpdate({ editor }) {
const wordCount = editor.state.doc.textContent.split(' ').length
console.log(wordCount)
},
})
```