/* Quick and dirty experiment: * Copy cells from a spreadsheet document (excel, libreoffice), and paste in a web page. * Replace the
in the cells with new lines, so when getting the innerHTML or the textContent, * the result is "formatted". */ document.addEventListener("paste", evt => { const content = evt.clipboardData.getData("text/html"); console.log("content:", content); const parser = new DOMParser(); const doc = parser.parseFromString(content, "text/html"); console.log("doc:", doc); const cells = doc.getElementsByTagName("td"); const firstCell = cells[1]; const newLine = document.createTextNode("*\n*"); const brList = firstCell.getElementsByTagName("br"); console.log("brList:", brList); Array.from(brList).map(n => n.parentNode.replaceChild(newLine.cloneNode(true), n)); console.log("firstCell html:", firstCell.innerHTML); console.log("firstCell text:", firstCell.textContent); }, false);