editor

Docs › Saving and output

Word count and limits

Status bar counts, maxLength and getStats.

The status bar under the editor shows characters, characters without spaces, words and bytes. For comments or short bios that need a length limit, set maxLength.

Try it

Code for this demo

createEditor('#editor', {
  toolbar: 'bold italic | link',
  maxLength: 100,
  height: 180,
});

How it counts

  • Characters: everything except line breaks. A Hangul syllable counts as one.
  • Without spaces: spaces and line breaks left out.
  • Words: runs of text separated by whitespace.
  • Bytes: UTF-8; a Hangul syllable is 3 bytes.

maxLength

With maxLength, the status bar reads like 87 / 100; past the limit the number and border turn red. Typing is not blocked. While over the limit, every change fires a maxlength event, which you can use to disable a submit button or show a hint.

const editor = createEditor('#editor', { maxLength: 2000 });

editor.on('maxlength', ({ length, max }) => {
  submit.disabled = true;
  hint.textContent = (length - max) + ' characters over';
});
editor.on('change', () => {
  if (editor.getStats().chars <= 2000) submit.disabled = false;
});

getStats()

editor.getStats();
// { chars: 87, charsNoSpace: 70, words: 18, bytes: 245, paragraphs: 2 }

paragraphs counts non-empty paragraphs, headings, list items, quotes and code blocks. Hide the bar with statusbar: false; the resize grip at the bottom goes with it.

Options

NameTypeDefaultDescription
statusbarbooleantrueShow the status bar (counts and resize grip)
maxLengthnumber-Character limit; over it the editor turns red and fires maxlength
getStats()method-{ chars, charsNoSpace, words, bytes, paragraphs }
maxlengthevent-{ length, max } on every change while over