Skip to content

gguridi/posthtml-nunjucks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PostHTML

PostHTML Nunjucks Plugin

A PostHTML plugin wrapping Nunjucks library.

npm GitHub Publish codecov

About

This is a PostHTML plugin that wraps Nunjucks library.

Introduction

This plugin applies a Nunjucks temple to the file being processed:

Input:

<div filter="uppercase">{{ name }}</div>

Output:

<div>TEST NAME</div>

Install

$ npm i posthtml posthtml-nunjucks

Usage

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>

Options

The options accepted for the plugin are:

config

Type: object
Default: {}

Configuration to be passed to nunjucks as specified here.

context

Type: object
Default: {}

Context to be passed to the templates to be applied, as specified here.