contentcollector: Factor out call to `.toLowerCase()`

This commit is contained in:
Richard Hansen 2021-01-21 02:27:15 -05:00 committed by John McLear
parent dd7fb1babe
commit 99625950c8
1 changed files with 4 additions and 3 deletions

View File

@ -43,7 +43,8 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author)
// .tagName works with DOM and cheerio 0.22.0, but:
// * With DOM, .tagName is an uppercase string.
// * With cheerio 0.22.0, .tagName is a lowercase string.
nodeTagName: (n) => n.tagName,
// For consistency, this function always returns a lowercase string.
nodeTagName: (n) => n.tagName && n.tagName.toLowerCase(),
// .nodeValue works with DOM and cheerio 0.22.0.
nodeValue: (n) => n.nodeValue,
// Returns the number of Node children (n.childNodes.length), not the number of Element children
@ -88,7 +89,7 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author)
_blockElems[element] = 1;
});
const isBlockElement = (n) => !!_blockElems[(dom.nodeTagName(n) || '').toLowerCase()];
const isBlockElement = (n) => !!_blockElems[dom.nodeTagName(n) || ''];
const textify = (str) => sanitizeUnicode(
str.replace(/(\n | \n)/g, ' ')
@ -406,7 +407,7 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author)
}
}
} else {
const tname = (dom.nodeTagName(node) || '').toLowerCase();
const tname = dom.nodeTagName(node) || '';
if (tname === 'img') {
hooks.callAll('collectContentImage', {