styles-from-html
v1.1.0
Published
Given html, will return all css styles from style tags as a concatenated string, as well as the resulting html with these style tags removed. Useful when you need to pass in css that is separated from html to another library while having declared css rule
Downloads
48
Maintainers
Readme
styles-from-html
Given html, will return all css styles from style tags as a concatenated string, as well as the resulting html with these style tags removed. Useful when you need to pass in css that is separated from html to another library while having declared css rules within embedded html documents (e.g. for request performance optimization).
Installation
npm install --styles-from-html
# or yarn add styles-from-html
Why not use cheer.io?
While it is generally frowned upon to use regular expressions for parsing HTML, this library makes a conscious choice to do so anyway, but only for the sole purpose of passing style tags. This results in significant performance improvements. A suite of tests is used to ensure the stability of the implementation. If you feel like there is any reason to use cheer.io or alternative HTML parsers anyway, please create a real world test case that does not resolve with the built-in regular expression.
Rebuilding API documentation
npm run docs
API documentation
ReturnObj
The return object containing the retrieved CSS and the HTML document without the CSS.
Type: Object
Properties
css
string The CSS retrieved from the HTML document.html
string The original HTML document with the retrieved CSS removed.
stylesFromHtml
A function that given HTML, will return an object with two properties: CSS, containing the css rules retrieved from the HTML document; and html, containing the original HTML document but with the retrieved CSS rules removed.
Parameters
html
type The input HTML document.
Returns ReturnObj An object containing the retrieved css and the HTML document without the CSS.