MCPcopy Create free account
hub / github.com/postlight/parser / removeAllButWhitelist

Function removeAllButWhitelist

src/utils/dom/clean-attributes.js:5–25  ·  view source on GitHub ↗
($article, $)

Source from the content-addressed store, hash-verified

3import { WHITELIST_ATTRS_RE, KEEP_CLASS } from './constants';
4
5function removeAllButWhitelist($article, $) {
6 $article.find('*').each((index, node) => {
7 const attrs = getAttrs(node);
8
9 setAttrs(
10 node,
11 Reflect.ownKeys(attrs).reduce((acc, attr) => {
12 if (WHITELIST_ATTRS_RE.test(attr)) {
13 return { ...acc, [attr]: attrs[attr] };
14 }
15
16 return acc;
17 }, {})
18 );
19 });
20
21 // Remove the mercury-parser-keep class from result
22 $(`.${KEEP_CLASS}`, $article).removeClass(KEEP_CLASS);
23
24 return $article;
25}
26
27// Remove attributes like style or align
28export default function cleanAttributes($article, $) {

Callers 1

cleanAttributesFunction · 0.85

Calls 3

getAttrsFunction · 0.90
setAttrsFunction · 0.90
$Function · 0.85

Tested by

no test coverage detected