9 Commits

Author SHA1 Message Date
Alexandre Gigliotti
4a3b6f9d50 0.1.6 2015-08-17 09:17:57 -07:00
Alexandre Gigliotti
5b88484888 Updated README. 2015-08-17 09:17:50 -07:00
Alexandre Gigliotti
dff5f1160b 0.1.5 2015-08-10 08:55:48 -07:00
Alexandre Gigliotti
abb3dd95a7 Updated README. 2015-08-10 08:55:40 -07:00
Alexandre Gigliotti
8f27f9d04f Updated README. 2015-08-06 08:37:37 -07:00
Alexandre Gigliotti
76ff6ca703 Updated README. 2015-08-05 16:16:35 -07:00
Alexandre Gigliotti
8e3a9b0390 0.1.4 2015-08-05 16:14:58 -07:00
Alexandre Gigliotti
56a6f43657 0.1.3 2015-08-05 16:10:27 -07:00
Alexandre Gigliotti
d5c6a6b540 Updated license. 2015-08-05 16:10:21 -07:00
3 changed files with 72 additions and 54 deletions

2
.gitignore vendored
View File

@@ -1,2 +1,4 @@
node_modules
.idea
*.log
test/test.html

116
README.md
View File

@@ -1,89 +1,105 @@
# inline-html
Embed local assets in an HTML document.
Inline local assets referenced in an HTML document.
[![npm](https://img.shields.io/npm/v/inline-html.svg)]()
[![Travis](https://img.shields.io/travis/panosoft/inline-html.svg)]()
[![David](https://img.shields.io/david/panosoft/inline-html.svg)]()
[![npm](https://img.shields.io/npm/dm/inline-html.svg)]()
[![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)
## Installation
npm install inline-html
```sh
npm install inline-html
```
## Usage
This:
Reads an HTML file, embeds the contents of local assets that are referenced within that file, and returns the inlined `html` string.
var inlineHtml = require('inline-html');
inlineHtml('path/to/file.html').then(function (html) {
...
});
The following elements and data types are inlined:
Turns this:
- LESS stylesheets - The LESS is compiled and the result is inlined within a `<style>` element.
- CSS url data types - The reference path is replaced with a datauri. These can be used in linked stylesheets, style elements, and element style attributes.
- Images - The source path is replaced with a datauri.
<link rel="stylesheet/less" href="main.less" />
Assuming we have the following files:
- `index.html`
```html
<link rel="stylesheet/less" href="main.less"/>
<style>
div { background-image: url('path/to/file'); }
</style>
<div style="background-image: url('path/to/file');"></div>
<img src="path/to/file" />
Into this:
<style>
@font-face { src: url('data:...'); }
div { background-image: url('data:...'); }
</style>
<style>
div { background-image: url('data:...'); }
</style>
<div style="background-image: url('data:...');"></div>
<img src="data:..." />
Where:
<img src="path/to/file"/>
```
- `main.less`
@import (inline) 'main.css';
div { background-image: url('path/to/file'); }
```css
@import (inline) 'main.css';
div { background-image: url('path/to/file'); }
```
- `main.css`
@font-face { src: url('path/to/file'); }
```css
@font-face { src: url('path/to/file'); }
```
We can use `inline-html`:
```js
var inlineHtml = require('inline-html');
inlineHtml('index.html').then(function (html) {
// ...
});
```
To create the following `html` string:
```html
<style>
@font-face { src: url('data:...'); }
div { background-image: url('data:...'); }
</style>
<style>
div { background-image: url('data:...'); }
</style>
<div style="background-image: url('data:...');"></div>
<img src="data:..."/>
```
## API
### inlineHtml( filename [, options] )
- [`inlineHtml`](#inlineHtml)
Reads an HTML file and embeds the contents of local assets referenced by the following elements and data types:
---
- LESS stylesheets - The LESS is compiled and the result is inlined within a `<style>` element.
<a name="inlineHtml"/>
### inlineHtml ( filename [, options] )
<link rel="stylesheet/less" href="main.less"/> -> <style>...</style>
Reads an HTML file and embeds referenced local assets into the HTML.
- CSS url data types - The reference path is replaced with a datauri. These can be used in linked stylesheets, style elements, and element style attributes.
Returns a `Promise` that is fulfilled with an `html` string or an instance of [`Results`](#Results) depending on the value of `options.verbose`.
url('file.ext') -> url('data:...')
- Images - The source path is replaced with a datauri.
<img src="file.ext"/> -> <img src="data:..."/>
Returns a `Promise` that is fulfilled with an `html` string or a `results` object depending on the value of `options.verbose`.
#### Arguments
__Arguments__
- `filename` - The filename of the HTML file to be inlined. Relative file paths are resolved relative to the filename 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. Defaults to `false`.
- `true`: promise is resolved with an instance of `Results`
- `false`: promise is resolved with `html`
- `verbose` - A boolean that determines the promises fulfillment value. Supported values are:
- `true`: An instance of [`Results`](#Results).
- `false`: An `html` string. (_default_)
#### Results object
<a name="Results"/>
__Results__
The `Promise` returned by this function is optionally fulfilled with a `results` object that has the following properties:
- `html` - The inlined html
- `files` - An array of filenames of the inlined local assets.
- `files` - An array of filenames for the local assets that were inlined.

View File

@@ -1,14 +1,14 @@
{
"name": "inline-html",
"version": "0.1.2",
"description": "Embed local assets in an HTML document.",
"version": "0.1.6",
"description": "Inline local assets referenced in an HTML document.",
"repository": "panosoft/inline-html",
"main": "lib/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"license": "MIT",
"dependencies": {
"cheerio": "^0.19.0",
"co": "^4.6.0",