Metalsmith plugin for adding syntax highlighting to code within posts
npm install metalsmith-code-highlight  
Finds content with elements and highlights it using HighlightJS.
Input:
`` Hello there.html`
Inline document.all
require "fs"
console.log fs.readFileSync "/etc/passwd"'
Output:
` Hello there.html`
Inline document.all
require "fs"
console.log fs.readFileSync "/etc/passwd"'
Supports the Highlight.js options (e.g. classPrefix, languages, tabReplace).
If you'd like to turn off automatic language detection, set {languages: []}. Only code blocks marked with an appropriate class like lang-js will be highlighted (useful when using fenced code blocks in Markdown).
By default, this plugin will highlight all code elements. You can override the selector for what to highlight by passing in a selector option like so: {selector: 'pre > code'}. This will only highlight
's immediatechildren elements. This is a metalsmith-code-highlight specific option—it isn't part of highlight.js.metalsmith-dom-transformUsing with
metalsmith-dom-transform, you can save a little bit of overhead by accessing the code highlight transform directly:`js`
const domTransform = require('metalsmith-dom-transform');
const codeHighlightTransform = require('metalsmith-code-highlight/transform');metalsmith.use(domTransform({
transforms: [
codeHighlightTransform(options),
// Your other transforms go here
]
}));1.1.1Changelog
*
: Update a bunch of dependencies1.1.0
*: Allow aselectoroption for overriding the default selector ofcode.1.0.3
*: Upgrade tometalsmith-dom-transform2.0.0, no functional changes1.0.2
*: Upgrade tometalsmith-dom-transform1.0.1, may cause slight change in HTML output when there is no content to highlight1.0.1
*: UsehighlightBlockfromhighlight.jsfor the highlighting, slight change in HTML output1.0.0
*: Upgrade tometalsmith-dom-transform1.0.0(API change)0.1.1
*: Upgrade dependencies0.1.0
*: Expose transform for use withmetalsmith-dom-transform`Alternatives
* metalsmith-metallic: Highlights only within Markdown