Sanitize user input

This commit is contained in:
Ramon Wenger 2022-01-20 17:20:34 +01:00
parent 7eab58ab88
commit b9ccf1700f
1 changed files with 6 additions and 0 deletions

View File

@ -1,6 +1,12 @@
const sanitize = html => {
let doc = new DOMParser().parseFromString(html, 'text/html');
return doc.body.textContent || '';
};
export const newLineToParagraph = (text) => {
return text
.split(/\n+/)
.map(sanitize)// sanitize after the split, because the sanitizer would probably remove the newlines
.map(p => `<p>${p}</p>`)
.join('');
};