replace-inline-css
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

replace-inline-css

This library allows you to replace all inline-css (<div style="...">) of a given html file with a single css class

  • Deletes all style properties from all the html elements
  • Adds a <style>{ ... }</style> with new css classes, containing all inline styles
  • Reuses classes when styles share the same properties and values
  • Magic

Installation

replace-inline-css requires Node.js v10+ to run.

yarn:

$ yarn add replace-inline-css

npm:

$ npm i replace-inline-css

Usage

Simply require the module and use it as a function.

const replaceInlineCss = require('replace-inline-css');

replaceInlineCss('./input.html', './output.html');

// Alternativley, you can pass an html string and play with the result

const newHtml = replaceInlineCss(html);
input.html:

style attributes all over:

Image of input.html

output.html:

Removed all style attributes & added references to new css classes:

Image of output.html

New <style> section added to the head:

Image of output.html

License

MIT

Free Software, Hell Yeah!

Package Sidebar

Install

npm i replace-inline-css

Weekly Downloads

0

Version

1.3.0

License

MIT

Unpacked Size

11.3 kB

Total Files

6

Last publish

Collaborators

  • sahar.avr