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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
16 additions and
16 deletions
-
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); |
|
|
|
|