JSFiddle - React, Tailwind, and code Playground

by Iván Pereira

HTML

<div id="container">
  
</div>

JavaScript

var str = "\tHi there &nbsp; how are you?\nI'am fine thanks.";

document.getElementById("container").innerHTML = html(str);

function html(str){
	return str.replace(/&/g, "&amp;").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
}