There is an editable div , in the sense of contentEditable . But when the user enters extra spaces, for example, then they then become special characters, and I cannot format the input. Screen attached. Please tell me how is treated

enter image description here

P.S. Tell me how to make a question, or at least tell me how these special characters of the space are called, and I will edit it.

 const editable = document.querySelector('.editable'); const output = document.querySelector('.output'); editable.oninput = function () { output.textContent = this.textContent.replace( / +/g, ' '); } 
 .editable { border:1px solid red; -webkit-user-modify: read-write; } 
 <div class="editable">редактируемое</div> <div class="output">редактируемое</div> 

  • what is the name I don’t know, but this is short for non-breaking space ie not a non-breaking space - user33274

1 answer 1

  1. .replace(/(\s)+/g, "$1")
  2. .replace(/\s+/g, " ")
  3. If the user enters something, then, probably, not just like that.