From 09c349e2a1342ddce2a4f6063bab4f27fc0275ac Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 29 Mar 2021 19:40:03 -0400 Subject: [PATCH] import: Use a Set for supported elements --- src/node/utils/ImportEtherpad.js | 4 ++-- src/static/js/contentcollector.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/node/utils/ImportEtherpad.js b/src/node/utils/ImportEtherpad.js index d47443733..459d5a38b 100644 --- a/src/node/utils/ImportEtherpad.js +++ b/src/node/utils/ImportEtherpad.js @@ -25,7 +25,7 @@ exports.setPadRaw = (padId, r) => { // get supported block Elements from plugins, we will use this later. hooks.callAll('ccRegisterBlockElements').forEach((element) => { - supportedElems.push(element); + supportedElems.add(element); }); Object.keys(records).forEach(async (key) => { @@ -64,7 +64,7 @@ exports.setPadRaw = (padId, r) => { if (value.pool) { for (const attrib of Object.keys(value.pool.numToAttrib)) { const attribName = value.pool.numToAttrib[attrib][0]; - if (supportedElems.indexOf(attribName) === -1) { + if (!supportedElems.has(attribName)) { console.warn('Plugin missing: ' + `You might want to install a plugin to support this node name: ${attribName}`); } diff --git a/src/static/js/contentcollector.js b/src/static/js/contentcollector.js index cf921cd47..1b7ef51d3 100644 --- a/src/static/js/contentcollector.js +++ b/src/static/js/contentcollector.js @@ -56,7 +56,7 @@ const getAttribute = (n, a) => { return null; }; // supportedElems are Supported natively within Etherpad and don't require a plugin -const supportedElems = [ +const supportedElems = new Set([ 'author', 'b', 'bold', @@ -76,7 +76,7 @@ const supportedElems = [ 'span', 'u', 'ul', -]; +]); const makeContentCollector = (collectStyles, abrowser, apool, className2Author) => { const _blockElems = { @@ -88,7 +88,7 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author) hooks.callAll('ccRegisterBlockElements').forEach((element) => { _blockElems[element] = 1; - supportedElems.push(element); + supportedElems.add(element); }); const isBlockElement = (n) => !!_blockElems[tagName(n) || '']; @@ -339,7 +339,7 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author) state.localAttribs = null; const isBlock = isBlockElement(node); if (!isBlock && node.name && (node.name !== 'body')) { - if (supportedElems.indexOf(node.name) === -1) { + if (!supportedElems.has(node.name)) { console.warn('Plugin missing: ' + `You might want to install a plugin to support this node name: ${node.name}`); }