|
1 | 1 | 'use strict'
|
2 | 2 |
|
| 3 | +const { forEach, flow, isEmpty, toLower } = require('lodash') |
3 | 4 | const sanitizeHtml = require('sanitize-html')
|
4 |
| -const { flow, isNil } = require('lodash') |
5 | 5 | const cheerio = require('cheerio')
|
6 | 6 |
|
7 |
| -const normalizeAttributes = propName => (tagName, attribs) => { |
8 |
| - if (!isNil(attribs[propName])) { |
9 |
| - attribs[propName] = attribs[propName].toLowerCase() |
10 |
| - } |
| 7 | +const normalizeAttributes = props => (tagName, attribs) => { |
| 8 | + forEach(props, propName => { |
| 9 | + if (!isEmpty(attribs[propName])) attribs[propName] = toLower(attribs[propName]) |
| 10 | + }) |
11 | 11 | return { tagName, attribs }
|
12 | 12 | }
|
13 | 13 |
|
14 | 14 | const sanitize = html =>
|
15 | 15 | sanitizeHtml(html, {
|
16 |
| - allowedTags: false, |
17 |
| - allowedAttributes: false, |
| 16 | + allowedTags: false, // allow all tags |
| 17 | + allowedAttributes: false, // allow all attributes |
18 | 18 | transformTags: {
|
19 |
| - meta: normalizeAttributes('name'), |
20 |
| - a: normalizeAttributes('href'), |
21 |
| - link: normalizeAttributes('rel') |
| 19 | + meta: normalizeAttributes(['name', 'property']), |
| 20 | + a: normalizeAttributes(['href']), |
| 21 | + link: normalizeAttributes(['rel']) |
22 | 22 | }
|
23 | 23 | })
|
24 | 24 |
|
|
0 commit comments