This is a PostHTML plugin that wraps Nunjucks library.
This plugin applies a Nunjucks temple to the file being processed:
Input:
<div filter="uppercase">{{ name }}</div>
Output:
<div>TEST NAME</div>
$ npm i posthtml posthtml-nunjucks
A simple plugin usage would be:
const posthtml = require('posthtml');
const nunjucks = require('posthtml-nunjucks');
posthtml([nunjucks({ context: { name: 'TEST NAME' } })])
.process('<div>{{ name }}</div>')
.then((result) => console.log(result.html));
// <div>TEST NAME</div>
The options accepted for the plugin are:
Type: object
Default: {}
Configuration to be passed to nunjucks as specified here.
Type: object
Default: {}
Context to be passed to the templates to be applied, as specified here.