contentcollector: Fix Element attribute accesses

The `attribs` property is only available on cheerio's Element-like
objects; DOM Element objects do not have an `attribs` property. Switch
to `dom.nodeAttr()` to fix the logic for browsers.
pull/4685/head
Richard Hansen 2021-01-21 00:30:55 -05:00 committed by John McLear
parent 99625950c8
commit 8763c3bb29
1 changed files with 4 additions and 4 deletions

View File

@ -491,14 +491,14 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author)
cc.doAttrib(state, 'strikethrough');
}
if (tname === 'ul' || tname === 'ol') {
let type = node.attribs ? node.attribs.class : null;
let type = dom.nodeAttr(node, 'class');
const rr = cls && /(?:^| )list-([a-z]+[0-9]+)\b/.exec(cls);
// lists do not need to have a type, so before we make a wrong guess
// check if we find a better hint within the node's children
if (!rr && !type) {
for (const i in node.children) {
if (node.children[i] && node.children[i].name === 'ul') {
type = node.children[i].attribs.class;
type = dom.nodeAttr(node.children[i], 'class');
if (type) {
break;
}
@ -509,8 +509,8 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author)
type = rr[1];
} else {
if (tname === 'ul') {
if ((type && type.match('indent')) ||
(node.attribs && node.attribs.class && node.attribs.class.match('indent'))) {
const cls = dom.nodeAttr(node, 'class');
if ((type && type.match('indent')) || (cls && cls.match('indent'))) {
type = 'indent';
} else {
type = 'bullet';