Skip to content

posthtml/posthtml-rename-attrs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PostHTML

posthtml-rename-attrs

Programmatically rename HTML attributes

Version Build License Downloads

About

This PostHTML plugin allows you to programmatically rename HTML attributes through a custom function.

Installation

npm i -D posthtml posthtml-rename-attrs

Usage

You simply define a function that returns the renamed attribute.

For example, let's rename all src attributes:

const posthtml = require('posthtml');
const renameAttrs = require('posthtml-rename-attrs');

// If the attribute is 'class', rename it
const prefix = (v) => v === 'src' ? `data-${v}` : v;

posthtml([renameAtrs(prefix)])
  .process('<img src="...">')
  .then(function(result) {
    console.log(result);
  });

Result:

<img data-src="...">

About

Programmatically rename HTML attributes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published