Browse Source

Support `attributes` option alongside `cleanId` for `toHTML` operations (#6642)

* Support `attributes` option alongside `cleanId` for `toHTML` operations

* whoops
release-v0.22.14-rc.3
David Harvey 3 months ago
committed by GitHub
parent
commit
0c33465fb3
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 32
      packages/core/src/code_manager/model/HtmlGenerator.ts

32
packages/core/src/code_manager/model/HtmlGenerator.ts

@ -27,22 +27,22 @@ export default class HTMLGenerator extends Model {
}) })
.filter(Boolean); .filter(Boolean);
if (!htmlOpts.attributes) { const attributes = htmlOpts.attributes;
htmlOpts.attributes = (mod, attrs) => { htmlOpts.attributes = (mod, attrs) => {
const { id } = attrs; attrs = typeof attributes === 'function' ? attributes(mod, attrs) : attrs;
if ( const { id } = attrs;
id && if (
id[0] === 'i' && // all autogenerated IDs start with 'i' id &&
!mod.get('script') && // if the component has script, we have to leave the ID id[0] === 'i' && // all autogenerated IDs start with 'i'
!mod.get('script-export') && // if the component has script, we have to leave the ID !mod.get('script') && // if the component has script, we have to leave the ID
!mod.get('attributes')!.id && // id is not intentionally in attributes !mod.get('script-export') && // if the component has script, we have to leave the ID
idRules.indexOf(id) < 0 // we shouldn't have any rule with this 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; ) {
} delete attrs.id;
return attrs; }
}; return attrs;
} };
} }
return model.toHTML(htmlOpts); return model.toHTML(htmlOpts);

Loading…
Cancel
Save