1.3.0 • Published 3 years ago

replace-inline-css v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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!