Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gguridi/posthtml-nunjucks
PostHTML plugin that wraps Nunjucks library.
https://github.com/gguridi/posthtml-nunjucks
Last synced: about 1 month ago
JSON representation
PostHTML plugin that wraps Nunjucks library.
- Host: GitHub
- URL: https://github.com/gguridi/posthtml-nunjucks
- Owner: gguridi
- License: mit
- Created: 2021-08-21T14:38:45.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-06T08:43:29.000Z (almost 2 years ago)
- Last Synced: 2024-09-28T17:04:41.986Z (3 months ago)
- Language: JavaScript
- Size: 253 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
PostHTML Nunjucks Plugin
A PostHTML plugin wrapping Nunjucks library.
[![npm](https://img.shields.io/npm/v/posthtml-nunjucks)](https://www.npmjs.com/package/posthtml-nunjucks)
![GitHub](https://img.shields.io/github/license/gguridi/posthtml-nunjucks)
[![Publish](https://github.com/gguridi/posthtml-nunjucks/actions/workflows/publish.yml/badge.svg?branch=master)](https://github.com/gguridi/posthtml-nunjucks/actions/workflows/publish.yml)
[![codecov](https://codecov.io/gh/gguridi/posthtml-nunjucks/branch/master/graph/badge.svg?token=BODGILME44)](https://codecov.io/gh/gguridi/posthtml-nunjucks)### About
This is a PostHTML plugin that wraps [Nunjucks](https://mozilla.github.io/nunjucks/) library.
## Introduction
This plugin applies a Nunjucks temple to the file being processed:
Input:
```html
{{ name }}
```Output:
```html
TEST NAME
```## Install
```
$ npm i posthtml posthtml-nunjucks
```## Usage
A simple plugin usage would be:
```js
const posthtml = require('posthtml');
const nunjucks = require('posthtml-nunjucks');posthtml([nunjucks({ context: { name: 'TEST NAME' } })])
.process('{{ name }}')
.then((result) => console.log(result.html));//
TEST NAME
```## Options
The options accepted for the plugin are:
### `config`
Type: `object`\
Default: `{}`Configuration to be passed to nunjucks as specified [here](https://mozilla.github.io/nunjucks/api.html#configure).
### `context`
Type: `object`\
Default: `{}`Context to be passed to the templates to be applied, as specified [here](https://mozilla.github.io/nunjucks/api.html#renderstring).