nunjucks-extension-code-highlight
Nunjucks extension to provide code highlighting.
Currently using hightlight.js for code highlight.
Install
npm i nunjucks-extension-code-highlight
Usage
Register the extension with nunjucks.
const nunjucks =const env = nunjucksenv
Add markdown to your templates.
Some example CSS
{% code %}
body {
background-color: white;
}
{% endcode %}
Some example SCSS
{% code %}
$bg: white;
body {
background-color: $bg;
}
{% endcode %}
Some example HTML
{% code %}
<section>
<h2>Sample</h2>
<a href="#">Link</a>
</section>
{% endcode %}
Options
You can pass a second argument to this extension to override a few defaults.
// Default optionstag: 'code'langs: 'xml' 'css' 'scss' 'javascript'// You could overwrite this wrap() to remove the <pre>{return `<pre></pre>`}
Also, you can access these from the nunjucks environment.
const codeExtension = envextensions'code-highlight'codeExtensionlangs = 'xml' // only auto-detect "xml"codeExtension v // no more <pre>...</pre>