XuelesszzZ 94af2b8e7b 6-30-5 | 1 rok temu | |
---|---|---|
.. | ||
CHANGELOG.md | 1 rok temu | |
LICENSE | 1 rok temu | |
README.md | 1 rok temu | |
index.js | 1 rok temu | |
package.json | 1 rok temu |
PostHTML 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)"
<style>
tag values like .selector {fill: url(#id)"}
attr="url(#id)"
Input
<style>
.selector {fill: url(#qwe)}
</style>
<div id="qwe"></div>
<a href="#qwe"></a>
Output
<style>
.selector {fill: url(#prefix_qwe)}
</style>
<div id="prefix_qwe"></div>
<a href="#prefix_qwe"></a>
npm install posthtml-rename-id
const posthtml = require('posthtml');
const rename = require('posthtml-rename-id');
posthtml()
.use(rename('prefix_[id]'))
.process('<div id="qwe"></div> <a href="#qwe"></a>')
.then(({ html }) => {
console.log(html); // <div id="prefix_qwe"></div> <a href="#prefix_qwe"></a>
});
pattern
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).
Uppercase all ids:
posthtml([
renameId(id => id.toUpperCase())
]);
Rename all ids to elem_{counter}
:
let c = 0;
posthtml([
renameId((id) => { c++; return 'elem_' + c; })
]);