From 0c33465fb370aee9ceb2a8648ee4f625b5d4add3 Mon Sep 17 00:00:00 2001 From: David Harvey Date: Fri, 14 Nov 2025 03:59:38 -0500 Subject: [PATCH] Support `attributes` option alongside `cleanId` for `toHTML` operations (#6642) * Support `attributes` option alongside `cleanId` for `toHTML` operations * whoops --- .../src/code_manager/model/HtmlGenerator.ts | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) 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);