ckeditor5

ckeditor5 统计文字

function() {

    function modelElementToPlainText(element) {

      if (element.is("text") || element.is("textProxy")) {

         return element.data;

      }

      let text = "";

      let prev = null;

      for (const child of element.getChildren()) {

         const childText = modelElementToPlainText(child);

         // If last block was finish, start from new line.

         if (prev && prev.is("element")) {

            text += "\\n";

         }

         text += childText;

         prev = child;

      }

      return text;

   }

   const txt = modelElementToPlainText(this.editor.model.document.getRoot());

   return txt.replace(/\\n/g, "").length;

}