JSFiddle - React, Tailwind, and code Playground
by Abhijeet Kandalkar
HTML
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div ><pre id="test">
Foo</pre></div>
<button type="button" onclick="get()">Get</button>
<button type="button" onclick="check()">check</button>
<button type="button" onclick="set()">Set</button>
<br>
<div id="console"></div>
<script>
var count = 0;
function get()
{
str = document.getElementById("test").innerHTML;
}
function check()
{
alert((str.match(/\n/g)||[]).length);
document.getElementById("console").innerHTML = str.replace(/(\r\n|\n|\r)/gm, "N");
}
function set()
{
setTimeout(function () {
//newstr = '\n' + str + '\n';
//alert(newstr.replace(/(\r\n|\n|\r)/gm, "N"));
document.getElementById("test").innerHTML = "\n\nA";
str = document.getElementById("test").innerHTML;
count++;
}, 100);
}
</script>
</body>
</html>
JavaScript
Node* parent = text.parentNode();
if (parent && parent->hasTagName(preTag) && text.data().startsWith('\n')) {
Node* firstChild = parent->firstChild();
if (firstChild && firstChild->isTextNode() && toText(firstChild) == text)
result.append('\n');
}