I have the following output :
(a lot of new lines here)
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy
text ever since the 1500s, when an unknown printer took
a galley of type and scrambled it to make a type specimen book.
(a lot of new lines here)
It has survived not only five centuries,
but also the leap into electronic typesetting,
remaining essentially unchanged. It was popularised
in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
To clean this up i am using a lot of regex
var body = contentDiv.replace(/ {2,}/g, ' ').replace(/([^\r\n][^\n])(?:\r?\n)([^\r\n][^\n])/g,"$1$2");
$('eBody').value = body.replace(/\n{3,}/g, '\n').replace(/^\s\s*/, '');
Where contentDiv
is the text above and is returned by a getElementsByTagName
.
var contentDiv = element.getElementsByTagName("div")[0].textContent;
It is just that the div has a lot of formatting ( ...), that when i call the textContent
function, I do get the text with spaces and extra new lines, normally it should look like:
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
.replace(/\s*(\r?\n){2,}\s*/g,"$1$1");
if that's what you're after? – MDEV