metalsmith-prism

Syntax highlighting for Metalsmith HTML templates using Prism.js

Usage no npm install needed!

<script type="module">
  import metalsmithPrism from 'https://cdn.skypack.dev/metalsmith-prism';
</script>

README

metalsmith-prism

Syntax highlighting for Metalsmith HTML templates using Prism.js

License NPM Dependency Status Linux Passing Windows Passing

Requirements

  • Node >= 4.x.x
  • NPM >= v3.x.x
  • Metalsmith >= v2.x.x

Quickstart

  • 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();
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();

Language support

Supports all programming languages that have a corresponding Prism.js component file. Component files are found in the Prism.js components directory.

Options

decode (optional)

  • Always decode the html entities when processing language of type markup
Metalsmith(__dirname)
  .use(metalsmithPrism({
    decode: true
  }))

lineNumbers (optional)

  • Appends class line-numbers to parent <pre> tag if present
Metalsmith(__dirname)
  .use(metalsmithPrism({
    lineNumbers: true
  }))

preLoad (optional)

  • 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"]
  }))

Authors

Robert McGuinness

Disclaimer

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.

Copyright and license

Code and documentation copyright 2017 Availity, LLC. Code released under the MIT license.