PostHTML plugin to rename id attributes and it's references
npm install posthtml-rename-idPostHTML plugin to rename id attributes
and it's references. Inspired by grunt-svgstore.
Handle following cases:
- href="#id" and xlink:href="#id"
- style attribute values like style="fill: url(#id)"
- tag values like .selector {fill: url(#id)"}
- any other attribute value like attr="url(#id)"
Input
``html
Output
`html
`Install
`sh
npm install posthtml-rename-id
`Usage
`js
const posthtml = require('posthtml');
const rename = require('posthtml-rename-id');posthtml()
.use(rename('prefix_[id]'))
.process('
')
.then(({ html }) => {
console.log(html); //
});
`Configuration
$3
> Type:
string | function
> Default: '[id]'Renaming pattern.
[id] placeholder can be used as current id of an element.
If pattern provided as a function it will be called with current id as first argument.
Function should return the new id as string ([id] can be used as well).Examples
Uppercase all ids:
`js
posthtml([
renameId(id => id.toUpperCase())
]);
`Rename all ids to
elem_{counter}:
`js
let c = 0;
posthtml([
renameId((id) => { c++; return 'elem_' + c; })
]);
``