diff --git a/src/code_manager/model/HtmlGenerator.js b/src/code_manager/model/HtmlGenerator.js index e8e728502..6206c6ec7 100644 --- a/src/code_manager/model/HtmlGenerator.js +++ b/src/code_manager/model/HtmlGenerator.js @@ -2,8 +2,8 @@ import { Model } from '../../common'; export default class HTMLGenerator extends Model { build(model, opts = {}) { - const htmlOpts = {}; - const { em } = opts; + const { em, ...restOpts } = opts; + const htmlOpts = restOpts; // Remove unnecessary IDs if (opts.cleanId && em) { @@ -17,19 +17,21 @@ export default class HTMLGenerator extends Model { }) .filter(i => i); - htmlOpts.attributes = (mod, attrs) => { - const { id } = attrs; - if ( - id && - id[0] === 'i' && // all autogenerated IDs start with 'i' - !mod.get('script') && // if the component has script, we have to leave the ID - !mod.get('attributes').id && // id is not intentionally in attributes - idRules.indexOf(id) < 0 // we shouldn't have any rule with this ID - ) { - delete attrs.id; - } - return attrs; - }; + if (!htmlOpts.attributes) { + htmlOpts.attributes = (mod, attrs) => { + const { id } = attrs; + if ( + id && + id[0] === 'i' && // all autogenerated IDs start with 'i' + !mod.get('script') && // if the component has script, we have to leave the ID + !mod.get('attributes').id && // id is not intentionally in attributes + idRules.indexOf(id) < 0 // we shouldn't have any rule with this ID + ) { + delete attrs.id; + } + return attrs; + }; + } } return model.toHTML(htmlOpts);