Syntax highlighting for Metalsmith HTML templates using Prism.js
- Node
>= 4.x.x
- NPM
>= v3.x.x
- Metalsmith
>= v2.x.x
- Install metalsmith-prism
npm install metalsmith-prism --save-dev
- Add language definition to code block
<code class="language-css">p { color: red }</code>
- Add
metalsmith-prism
plugin to metalsmith
const metalsmith = require('metalsmith');
const metalsmithPrism = require('metalsmith-prism');
metalsmith(__dirname)
.use(metalsmithPrism())
.build();
- OPTIONAL To use with Markdown code blocks rendered by metalsmith-markdown
const metalsmith = require('metalsmith');
const markdown = require('metalsmith-markdown');
const metalsmithPrism = require('metalsmith-prism');
metalsmith(__dirname)
// Custom langPrefix option needed as markdown uses 'lang-' by default:
.use(markdown( { langPrefix: 'language-' } ))
.use(metalsmithPrism())
.build();
Supports all programming languages that have a corresponding Prism.js component file. Component files are found in the Prism.js components
directory.
- Always decode the html entities when processing language of type
markup
Metalsmith(__dirname)
.use(metalsmithPrism({
decode: true
}))
- Appends class
line-numbers
to parent<pre>
tag if present
Metalsmith(__dirname)
.use(metalsmithPrism({
lineNumbers: true
}))
- Pre-loads language component(s), such that each language component registers itself in the order given in the input array
- Useful for loading syntax that extends other language components that are not automatically registered by Prism
Metalsmith(__dirname)
.use(metalsmithPrism({
preLoad: ["java", "scala"]
}))
Robert McGuinness
Open source software components distributed or made available in the Availity Materials are licensed to Company under the terms of the applicable open source license agreements, which may be found in text files included in the Availity Materials.
Code and documentation copyright 2017 Availity, LLC. Code released under the MIT license.