mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-15 02:59:01 +08:00
5daa870b09
* fix a bug when exceeding the character limit * find a better way to limit the doc size * check paste events * add storage method * refactoring * use textBetween instead of textContent * return early if no limit is set * add words method to storage * show word count in charactercount demo Co-authored-by: Philipp Kühn <philippkuehn@MacBook-Pro-von-Philipp.local>
1.7 KiB
1.7 KiB
description | icon |
---|---|
Limit the number of characters in your editor, or at least count them. | calculator-line |
CharacterCount
The CharacterCount
extension limits the number of allowed character to a specific length. That’s it, that’s all.
Installation
npm install @tiptap/extension-character-count
Settings
limit
The maximum number of characters that should be allowed.
Default: 0
CharacterCount.configure({
limit: 240,
})
mode
The mode by which the size is calculated.
Default: 'textSize'
CharacterCount.configure({
mode: 'nodeSize',
})
Storage
characters()
Get the number of characters for the current document.
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.
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/