import: Use a Set for supported elements

This commit is contained in:
Richard Hansen 2021-03-29 19:40:03 -04:00 committed by webzwo0i
parent e31da37d00
commit 09c349e2a1
2 changed files with 6 additions and 6 deletions

View file

@ -25,7 +25,7 @@ exports.setPadRaw = (padId, r) => {
// get supported block Elements from plugins, we will use this later. // get supported block Elements from plugins, we will use this later.
hooks.callAll('ccRegisterBlockElements').forEach((element) => { hooks.callAll('ccRegisterBlockElements').forEach((element) => {
supportedElems.push(element); supportedElems.add(element);
}); });
Object.keys(records).forEach(async (key) => { Object.keys(records).forEach(async (key) => {
@ -64,7 +64,7 @@ exports.setPadRaw = (padId, r) => {
if (value.pool) { if (value.pool) {
for (const attrib of Object.keys(value.pool.numToAttrib)) { for (const attrib of Object.keys(value.pool.numToAttrib)) {
const attribName = value.pool.numToAttrib[attrib][0]; const attribName = value.pool.numToAttrib[attrib][0];
if (supportedElems.indexOf(attribName) === -1) { if (!supportedElems.has(attribName)) {
console.warn('Plugin missing: ' + console.warn('Plugin missing: ' +
`You might want to install a plugin to support this node name: ${attribName}`); `You might want to install a plugin to support this node name: ${attribName}`);
} }

View file

@ -56,7 +56,7 @@ const getAttribute = (n, a) => {
return null; return null;
}; };
// supportedElems are Supported natively within Etherpad and don't require a plugin // supportedElems are Supported natively within Etherpad and don't require a plugin
const supportedElems = [ const supportedElems = new Set([
'author', 'author',
'b', 'b',
'bold', 'bold',
@ -76,7 +76,7 @@ const supportedElems = [
'span', 'span',
'u', 'u',
'ul', 'ul',
]; ]);
const makeContentCollector = (collectStyles, abrowser, apool, className2Author) => { const makeContentCollector = (collectStyles, abrowser, apool, className2Author) => {
const _blockElems = { const _blockElems = {
@ -88,7 +88,7 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author)
hooks.callAll('ccRegisterBlockElements').forEach((element) => { hooks.callAll('ccRegisterBlockElements').forEach((element) => {
_blockElems[element] = 1; _blockElems[element] = 1;
supportedElems.push(element); supportedElems.add(element);
}); });
const isBlockElement = (n) => !!_blockElems[tagName(n) || '']; const isBlockElement = (n) => !!_blockElems[tagName(n) || ''];
@ -339,7 +339,7 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author)
state.localAttribs = null; state.localAttribs = null;
const isBlock = isBlockElement(node); const isBlock = isBlockElement(node);
if (!isBlock && node.name && (node.name !== 'body')) { if (!isBlock && node.name && (node.name !== 'body')) {
if (supportedElems.indexOf(node.name) === -1) { if (!supportedElems.has(node.name)) {
console.warn('Plugin missing: ' + console.warn('Plugin missing: ' +
`You might want to install a plugin to support this node name: ${node.name}`); `You might want to install a plugin to support this node name: ${node.name}`);
} }