# inline-html Inline local assets referenced in an HTML document. [![npm version](https://img.shields.io/npm/v/inline-html.svg)](https://www.npmjs.com/package/inline-html) [![npm license](https://img.shields.io/npm/l/inline-html.svg)](https://www.npmjs.com/package/inline-html) [![Travis](https://img.shields.io/travis/panosoft/inline-html.svg)](https://travis-ci.org/panosoft/inline-html) [![David](https://img.shields.io/david/panosoft/inline-html.svg)](https://david-dm.org/panosoft/inline-html) [![npm downloads](https://img.shields.io/npm/dm/inline-html.svg)](https://www.npmjs.com/package/inline-html) This library parses HTML, embeds the contents of local assets that are referenced within that HTML, and returns a new inlined HTML string. The following HTML elements and CSS data types are inlined: - Images - The source path is replaced with a datauri. - Linked LESS stylesheets - The LESS is compiled and the result is inlined within a `
`; html = yield inline.html(html); console.log(html); /**
*/ }); ``` ## Installation ```sh npm install inline-html ``` ## API - [`inline.html`](#html) - [`inline.file`](#file) - [`Results`](#results) --- ### inline.html ( html [, options] ) Parses an HTML string and embeds referenced local assets into the HTML. Returns a `Promise` that is fulfilled with an `html` string or an instance of [`Results`](#results) depending on the value of `options.verbose`. __Arguments__ - `html` - An HTML string to inline. - `options` - `filename` - The filename used to resolve relative paths. If this option is not provided, relative paths will be resolved relative to the process's current working directory. - `less` - An object containing LESS options to pass to the less compiler. Defaults to `{}`. - `verbose` - A boolean that determines the promises fulfillment value. Supported values are: - `true`: An instance of [`Results`](#results). - `false`: An `html` string. (_Default_) __Example__ ```js co(function * () { var html = yield inline.html(``); console.log(html); // }); ``` --- ### inline.file ( filename [, options] ) Reads an HTML file and embeds referenced local assets into the HTML. Returns a `Promise` that is fulfilled with an `html` string or an instance of [`Results`](#results) depending on the value of `options.verbose`. __Arguments__ - `html` - A filename of an HTML file to inline. Relative file paths are resolved relative to the filename's directory. - `options` - `less` - An object containing LESS options to pass to the less compiler. Defaults to `{}`. - `verbose` - A boolean that determines the promises fulfillment value. Supported values are: - `true`: An instance of [`Results`](#results). - `false`: An `html` string. (_Default_) __Example__ ```js co(function * () { html = yield inline.file(`index.html`); console.log(html); // }); ``` --- ### Results The `Promise` returned by these functions is optionally fulfilled with a `results` object that has the following properties: - `html` - The inlined html - `files` - An array of filenames for the local assets that were inlined.