wix-incubator / react-native-zss-rich-text-editor

React Native rich text editor based on ZSSRichTextEditor
Other
841 stars 310 forks source link

Getting the character limit of the editor #136

Open adelumban-sp opened 6 years ago

adelumban-sp commented 6 years ago

Is there there's to get the editor's text limit? The document doesn't have it.. is there a way to do this. I log the text thru listener and the text in the listener is giving the html equivalent of what is being rendered.

adelumban-sp commented 6 years ago

I think I solved my problem for now what i did was removed all the tags and replace some characters.

 this.richtext.registerContentChangeListener((str) => {

       const regex = /(<([^>]+)>)/ig;
           const result = str.replace(regex, '')
                      .replace('&nbsp;', " ")
                      .replace('&lt;', "<")
                      .replace('&gt;', ">")
                      .replace('&amp;', '&');

          return result.length;
  });