MCPcopy Create free account
hub / github.com/ampproject/amphtml / cleanHtml

Function cleanHtml

testing/helpers/cleanHtml.ts:7–16  ·  view source on GitHub ↗
(html: string, keepAttrs?: string[])

Source from the content-addressed store, hash-verified

5 * @param [keepAttrs] - An optional array of attributes to keep
6 */
7export 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
18export function cleanWhitespace(html: string): string {
19 return html.trim().replace(/\s\s+/g, ' ');

Callers 4

snapshotFunction · 0.90
test-amp-list.jsFile · 0.90
snapshotFunction · 0.90
snapshotFunction · 0.90

Calls 2

cleanWhitespaceFunction · 0.85
replaceMethod · 0.45

Tested by

no test coverage detected