I want to render a block of text exactly as it's written into an HTML element. So if there are multiple consecutive spaces, I want to render all the spaces, rather than truncating them to a single space, as is the default. I cannot simply replace the spaces with , as that would, ahem, not break lines. I still want line breaks to occur naturally. How would I go about doing this in JavaScript?
text.replace(/ /g, " ") - doesn't break lines.
I also tried: text.replace(/ /g, " "), which gave the same result as the default behavior - truncating multiple spaces into a single space.
white-space: pre;css rule be relevant to your usage? Not quite what you asked for, but could be what you need.prewould not break lines; what OP wants ispre-wrap.