Basically I just need the effect of copying that HTML from browser window and pasting it in a textarea element.
For example I want this:
Som
I made a function based on this answer: https://stackoverflow.com/a/42254787/3626940
function htmlToText(html){
//remove code brakes and tabs
html = html.replace(/\n/g, "");
html = html.replace(/\t/g, "");
//keep html brakes and tabs
html = html.replace(/<\/td>/g, "\t");
html = html.replace(/<\/table>/g, "\n");
html = html.replace(/<\/tr>/g, "\n");
html = html.replace(/<\/p>/g, "\n");
html = html.replace(/<\/div>/g, "\n");
html = html.replace(/<\/h>/g, "\n");
html = html.replace(/
/g, "\n"); html = html.replace(/
/g, "\n");
//parse html into text
var dom = (new DOMParser()).parseFromString('' + html, 'text/html');
return dom.body.textContent;
}