aswi2022code-of-duty-gitlab/frontend/src/utils/formatting/HtmlUtils.tsx @ ff40cb89
1 |
import DOMPurify from 'dompurify' |
---|---|
2 |
import { ReactNode } from 'react' |
3 |
|
4 |
/**
|
5 |
* Formats HTML string to safe virtual DOM nodes.
|
6 |
* @param htmlString string to format
|
7 |
*/
|
8 |
export const formatHtmlStringToReactDom = (htmlString: string, defaultValue: string = '-'): ReactNode => { |
9 |
if (!htmlString || htmlString.length === 0) { |
10 |
return defaultValue |
11 |
}
|
12 |
return ( |
13 |
<div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(htmlString) }} /> |
14 |
)
|
15 |
}
|