Sanitize user input
This commit is contained in:
parent
7eab58ab88
commit
b9ccf1700f
|
|
@ -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('');
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue