Skip to content

tommedema/html-embed-stylesheets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published