# nunjucks-markdown

> A markdown extension for nunjucks

Latest version **2.0.1** (published 2016-11-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install nunjucks-markdown
pnpm add nunjucks-markdown
yarn add nunjucks-markdown
bun add nunjucks-markdown
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2016-11-07 |
| First published | 2014-10-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 47 |
| Author | Zephraph |
| Maintainers | zephraph |
| Keywords | nunjucks, markdown |

## Links

- npm: https://www.npmjs.com/package/nunjucks-markdown
- Repository: https://github.com/zephraph/nunjucks-markdown
- Issues: https://github.com/zephraph/nunjucks-markdown/issues
- npm.io page: https://npm.io/package/nunjucks-markdown

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 2.0.1 (latest) — 2016-11-07
- 2.0.0 — 2016-03-05
- 1.1.0 — 2015-05-29
- 1.0.0 — 2015-01-15
- 0.7.0 — 2015-01-11
- 7.0.0 — 2015-01-11
- 0.5.2 — 2014-10-28
- 0.5.1 — 2014-10-24

## README

# nunjucks-markdown [![Build Status](https://travis-ci.org/zephraph/nunjucks-markdown.svg)](https://travis-ci.org/zephraph/nunjucks-markdown)

A nunjuck extension that adds a markdown tag. This plugin allows you to choose your own markdown renderer.

## Install

``` bash
npm install nunjucks-markdown --save
```

## Usage

Register the extension with nunjucks

``` js
var nunjucks = require('nunjucks'),
    markdown = require('nunjucks-markdown'),
    marked = require('marked');

var env = nunjucks.configure('views');

// The second argument can be any function that renders markdown
markdown.register(env, marked);
```

Add markdown to your templates

```
{% markdown %}
Hello World
===========
# Do stuff
{% endmarkdown %}
```

You can also provide the markdown tag with a template to render

```
{% markdown "post.md" %}
```
_Note: This method doesn't require a closing tag_

As you would expect, you can add tags inside your markdown tag
```
{% markdown %}
{% include 'post1.md' %}
{% include 'post2.md' %}
{% endmarkdown %}
```

### Using with Gulp

Gulp requires a little more explicit settings than standard npm. See https://mozilla.github.io/nunjucks/api.html#custom-tags

see example-gulpefile.js based on https://gist.github.com/kerryhatcher/1382950af52f3082ecdc668bba5aa11b

``` js
var nunjucks = require('nunjucks'),
    markdown = require('nunjucks-markdown'),
    marked = require('marked'),
    gulpnunjucks = require('gulp-nunjucks');
    
var templates = 'src/templates'; //Set this as the folder that contains your nunjuck files

var env = new nunjucks.Environment(new nunjucks.FileSystemLoader(templates));

// The second argument can be any function that renders markdown
markdown.register(env, marked);

gulp.task('pages', function() {
    // Gets .html files. see file layout at bottom
    return gulp.src([templates + '/*.html', templates + '/**/*.html'])
        // Renders template with nunjucks and marked
        .pipe(gulpnunjucks.compile("", {env: env}))
        // output files in dist folder
        .pipe(gulp.dest(dist))
});
```


## Markdown Options

**Nunjucks-markdown** doesn't require you to use any particular markdown renderer. If you were to use marked here's a good example of how it could be configured.

``` js
var marked = require('marked');

marked.setOptions({
  renderer: new marked.Renderer(),
  gfm: true,
  tables: true,
  breaks: false,
  pendantic: false,
  sanitize: true,
  smartLists: true,
  smartypants: false
});

markdown.register(env, marked);
```

For more information configuration options, checkout [marked](https://github.com/chjj/marked).

---
_Source: https://npm.io/package/nunjucks-markdown · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
