I'm using this function to extract the Text from the Textareas in my project (to avoid saving the copied text styling in the database),
export const stripHTML = (text) => {
// eslint-disable-next-line no-var
var temporalDivElement = document.createElement("div");
temporalDivElement.innerHTML = text;
return temporalDivElement.textContent || temporalDivElement.innerText || "";
};
The problem is that now the user can't write any line breaks in the text. What is the best way to solve that so I get a clean text but with the line breaks?
` with `\n\r` and then do the text conversion. Will lose automatic breaks from block elements. Another approach is parse all the elements and remove their attributes and save as html – charlietfl Aug 09 '20 at 16:59