Detalhes do pacote

posthtml-rename-id

JetBrains1.1mMIT1.0.12

PostHTML plugin to rename id attributes and it's references

posthtml, posthtml plugin

readme (leia-me)

posthtml-rename-id

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)"}
  • any other attribute value like attr="url(#id)"

Demo

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>

Install

npm install posthtml-rename-id

Usage

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>
  });

Configuration

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).

Examples

Uppercase all ids:

posthtml([
  renameId(id => id.toUpperCase())
]);

Rename all ids to elem_{counter}:

let c = 0;
posthtml([
  renameId((id) => { c++; return 'elem_' + c; })
]);

LICENSE

MIT

changelog (log de mudanças)

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

1.0.12 (2020-04-03)

Note: Version bump only for package posthtml-rename-id

1.0.11 (2018-12-05)

Note: Version bump only for package posthtml-rename-id

1.0.10 (2018-10-29)

Note: Version bump only for package posthtml-rename-id

1.0.9 (2018-10-29)

Bug Fixes

  • refer to license file in readme (e34a289)

1.0.8 (2018-06-18)

Bug Fixes

  • handle for attr in label tag (769fb73), closes #27

1.0.7 (2018-05-11)

Note: Version bump only for package posthtml-rename-id

1.0.6 (2018-04-28)

Note: Version bump only for package posthtml-rename-id

1.0.5 (2018-04-21)

Note: Version bump only for package posthtml-rename-id

1.0.4 (2018-04-13)

Note: Version bump only for package posthtml-rename-id

1.0.4-alpha.0 (2018-04-09)

Note: Version bump only for package posthtml-rename-id

1.0.3 (2017-05-16)

Bug Fixes

  • symboId not prepended to clipPath IDs in url(...) (9e685b4)