(html: string, keepAttrs?: string[])
| 5 | * @param [keepAttrs] - An optional array of attributes to keep |
| 6 | */ |
| 7 | export function cleanHtml(html: string, keepAttrs?: string[]): string { |
| 8 | html = html.replace(/\s([-\w]+)(="[^"]*")/g, ($0, $attr) => { |
| 9 | return keepAttrs?.includes($attr) ? $0 : ''; |
| 10 | }); |
| 11 | |
| 12 | // Condense whitespace: |
| 13 | html = cleanWhitespace(html); |
| 14 | |
| 15 | return html; |
| 16 | } |
| 17 | |
| 18 | export function cleanWhitespace(html: string): string { |
| 19 | return html.trim().replace(/\s\s+/g, ' '); |
no test coverage detected