($article, $)
| 3 | import { WHITELIST_ATTRS_RE, KEEP_CLASS } from './constants'; |
| 4 | |
| 5 | function 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 |
| 28 | export default function cleanAttributes($article, $) { |
no test coverage detected