is inserted instead of the white-space for the redactor-js

229 Views Asked by At

Why   is inserted instead of the white-space after inserting the second space in the row between two words or numbers, e.g. 1 2. When I click on the HTML button I see 1  2. I think it is correct behavior but I don't understand does this happen because of the browser or there's any flag in the code which turn it on? I didn't find any documentation for the redactor-js.

Please find the source code by link https://github.com/html5cat/redactor-js

Please find the redactor (a new version) by link https://imperavi.com/redactor/

Steps to reproduce:

  1. open the link https://imperavi.com/redactor/
  2. clear the redactor
  3. write 1 2 (two spaces between)
  4. click on the HTML button
  5. check that there's 1  2 instead of 1 2

enter image description here

enter image description here

1

There are 1 best solutions below

3
On

Its because in html when you have multiple spaces the browser will strip them out.

The &nsbp; is a html entity called a non-breaking space that allows programmers to over come this intended functionality.

https://www.w3schools.com/html/html_entities.asp

In this instance as its a WYSIWYG, it will replace multiple [space]'s with the html entity so that it displays as the user intends.

Specifically in this instance its handled by the browser and the "contenteditable" attribute.

https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Editable_content