diff --git a/packages/core/src/code_manager/model/HtmlGenerator.ts b/packages/core/src/code_manager/model/HtmlGenerator.ts index 177203e8c..ebd4981f1 100644 --- a/packages/core/src/code_manager/model/HtmlGenerator.ts +++ b/packages/core/src/code_manager/model/HtmlGenerator.ts @@ -27,22 +27,22 @@ export default class HTMLGenerator extends Model { }) .filter(Boolean); - 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('script-export') && // 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; - }; - } + const attributes = htmlOpts.attributes; + htmlOpts.attributes = (mod, attrs) => { + attrs = typeof attributes === 'function' ? attributes(mod, attrs) : 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('script-export') && // 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);