Have ideas to improve npm?Join in the discussion! »

    styles-from-html

    1.1.0 • Public • Published

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

    JavaScript Style Guide

    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.

    Install

    npm i styles-from-html

    DownloadsWeekly Downloads

    3

    Version

    1.1.0

    License

    MIT

    Last publish

    Collaborators

    • avatar