JiHong88 / suneditor

Pure javascript based WYSIWYG html editor, with no dependencies.
http://suneditor.com
MIT License
1.67k stars 308 forks source link

character count != editor.getContents().length when using "byte-html" #1322

Open SvV-CWinJS opened 8 months ago

SvV-CWinJS commented 8 months ago

Describe the bug In the resize bar, one can let the number of characters be shown. The characters counted as "byte-html" as stated there is (in some cases) larger than when doing editor.getContents().length.

It was noted these attributes were not present in the image when calling editor.getContents(): data-rotatex="" data-rotatey="" data-index="0". There could be more attributes missing.

To Reproduce (Only tested when inserting an image)

  1. Initialize the editor with the image plugin and {maxCharCount: 100000, charCounterType: "byte-html"}
  2. Insert an image from disk (using the button from the toolbar) [it should be inserted using base64-encoding]
  3. See the number of "characters" as stated in the resizebar below
  4. Compare this number with the number when calling editor.getContents().length

Expected behavior Presuming calling editor.getContents() is the way to go to extract what was entered (as what is to be saved in a database, for example), I expect the user to be able to accurately see how many characters he is "consuming" (also when putting in media).

Screenshots image

Desktop: