Nonlinear Programming Methods

    html-embed-stylesheets

    1.3.0 • Public • Published

    html-embed-stylesheets

    Insert html and receive back html with all stylesheets embedded. Can resolve relative urls inside stylesheets to a given root url.

    Improvements

    • consider @import statements inside stylesheets
    • improve css url regex to not capture whitespace after uri, e.g. in case of url( https://img.itch.zone/aW1hZ2UvMTgyMjY4Lzg1MTg3MC5wbmc=/300x240%23c/EWraUT.png );

    Table of Contents

    embedStylesheets

    Insert html and receive back html with all stylesheets embedded. Can resolve relative urls inside stylesheets to a given root url.

    Parameters

    • html string the HTML to parse for stylesheets
    • opts {resolveTo: string, download: Boolean} object with options. resolveTo defines to which root url discovered urls in stylesheets should be resolved. download defines whether resolved stylesheets should be downloaded and embedded, defaults to true.

    Examples

    const embedStylesheets = require('html-embed-stylesheets')
     
    async function main () {
      const { html } = await embedStylesheets(html, { resolveTo: 'https://www.example.com' })
      console.log(html)
    }
     
    main()

    Returns {html: string, stylesheetUrls: [string], stylesheets: [string]} an object returning the html with stylesheets embedded, an array of unique stylesheet urls that were found, and an array of stylesheets with inner urls resolved.

    Install

    npm i html-embed-stylesheets

    DownloadsWeekly Downloads

    1

    Version

    1.3.0

    License

    MIT

    Unpacked Size

    714 kB

    Total Files

    54

    Last publish

    Collaborators

    • tommedema