2.1.1 • Published 8 years ago

metalsmith-prismjs v2.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

metalsmith-prism

Syntax highlighting for Metalsmith HTML templates using Prism.js

License NPM Dependency Status Linux Passing Windows Passing

Quickstart

  • Install metalsmith-prism with npm
  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
var metalsmith = require('metalsmith');
var metalsmithPrism = require('metalsmith-prism');
metalsmith(__dirname)
  .use(metalsmithPrism())
  .build();
var metalsmith = require('metalsmith');
var markdown = require('metalsmith-markdown');
var 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.

JSON

JSON syntax highlighting is enhanced using the following syntax definition

Prism.languages.json = {
  'keys': /".+"(?=:)/g,
  'boolean': /\b(true|false)/g,
  'punctuation': /({|}|:|\[|\]|,)/g,
  'keyword': /\b(null)\b/g
}
<code class="language-json">
{
    ping: "pong"
}
</code>

Options

decode (optional)

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

json (optional)

  • Supply custom JSON syntax definition
Metalsmith(__dirname)
  .use(metalsmithPrism({
    json: {
      'keys': /".+"(?=:)/g,
      'boolean': /\b(true|false)/g,
      'punctuation': /({|}|:|\[|\]|,)/g,
      'keyword': /\b(null)\b/g
    }
  }))

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 2015 Availity, LLC. Code released under the MIT license.