Skip to content

posthtml/posthtml-include

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PostHTML Include

Include partials into your posthtml templates

NPM Deps Tests Coverage

Install

npm install posthtml-include --save

Usage

Given the following input files:

<!-- index.html -->
<p>Here's my partial:</p>
<include src='_partial.html'></include>
<p>after the partial</p>
<!-- _partial.html -->
<strong>hello from the partial!</strong>

Process them with posthtml:

const {readFileSync} = require('fs')
const posthtml = require('posthtml')
const include = require('posthtml-include')

const html = readFileSync('index.html')

posthtml({ plugins: include() })
  .process(html)
  .then((result) => console.log(result.output()))

Output:

<p>Here's my partial:</p>
<strong>hello from the partial!</strong>
<p>after the partial</p>

Options

All options are optional, none are required.

Name Description Default
root Root path to resolve the include from the file's path
addDependencyTo Object with addDependency() method, taking file path as an argument. Called whenever a file is included

License

Licensed under MIT