All Projects → fortes → metalsmith-code-highlight

fortes / metalsmith-code-highlight

Licence: ISC License
Metalsmith plugin for syntax highlighting code with HTML

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to metalsmith-code-highlight

headings
A Metalsmith plugin that extracts headings from HTML files and attaches them to the file's metadata.
Stars: ✭ 22 (+57.14%)
Mutual labels:  metalsmith
metalsmith-html-minifier
A Metalsmith plug-in to minify HTML files
Stars: ✭ 23 (+64.29%)
Mutual labels:  metalsmith
permalinks
A Metalsmith plugin for permalinks.
Stars: ✭ 61 (+335.71%)
Mutual labels:  metalsmith
streetsupport-web
Helping people facing homelessness across the UK to find services in their area, and connecting people who want to help to where it is needed most.
Stars: ✭ 21 (+50%)
Mutual labels:  metalsmith
metalsmith-jquery
A Metalsmith plugin to manipulate HTML via jQuery syntax
Stars: ✭ 13 (-7.14%)
Mutual labels:  metalsmith
markdown
A metalsmith plugin to render markdown files to HTML.
Stars: ✭ 58 (+314.29%)
Mutual labels:  metalsmith
metalsmith-convert
Convert images with imagemagick (via imagemagick-native).
Stars: ✭ 17 (+21.43%)
Mutual labels:  metalsmith
directus-metalsmith-snipcart
Lookbook web app with Directus' open source headless CMS, Metalsmith, Vue.js & Snipcart
Stars: ✭ 14 (+0%)
Mutual labels:  metalsmith
metalsmith-paths
Metalsmith plugin that adds file path values to metadata
Stars: ✭ 19 (+35.71%)
Mutual labels:  metalsmith
metalsmith-request
Metalsmith plugin to grab content from the web and expose the results to metadata
Stars: ✭ 12 (-14.29%)
Mutual labels:  metalsmith
metalsmith-imagemin
Metalsmith plugin to minify images
Stars: ✭ 17 (+21.43%)
Mutual labels:  metalsmith
remove
A Metalsmith plugin to remove files from the build
Stars: ✭ 19 (+35.71%)
Mutual labels:  metalsmith
Staticman
💪 User-generated content for Git-powered websites
Stars: ✭ 2,098 (+14885.71%)
Mutual labels:  metalsmith
Gray Matter
Contributing Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Stars: ✭ 2,105 (+14935.71%)
Mutual labels:  metalsmith
Metalsmith
An extremely simple, pluggable static site generator.
Stars: ✭ 7,692 (+54842.86%)
Mutual labels:  metalsmith
metalsmith-babel
A Metalsmith plugin to compile JavaScript with Babel
Stars: ✭ 19 (+35.71%)
Mutual labels:  metalsmith
metalsmith
An extremely simple, pluggable static site generator.
Stars: ✭ 7,721 (+55050%)
Mutual labels:  metalsmith

metalsmith-code-highlight

build status codecov Greenkeeper badge

Finds content with <code> elements and highlights it using HighlightJS.

Example

Input:

<p>Hello there.</p>
<p>
  Inline <code class=lang-js>document.all</code>
</p>
<pre>
  <code class=lang-coffeescript>
    require "fs"
    console.log fs.readFileSync "/etc/passwd"'
  </code>
</pre>

Output:

<p>Hello there.</p>
<p class="lang-highlight">
  Inline <code class="lang-js hljs javascript"><span class="hljs-built_in">document</span>.all</code>
</p>
<pre class="lang-highlight">
  <code class="lang-coffeescript hljs">
    <span class="hljs-built_in">require</span> <span class="hljs-string">"fs"</span>
    <span class="hljs-built_in">console</span>.log fs.readFileSync <span class="hljs-string">"/etc/passwd"</span><span class="hljs-string">'</span>
  </code>
</pre>

Configuration

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 <pre>'s immediate <code> children elements. This is a metalsmith-code-highlight specific option—it isn't part of highlight.js.

Using with metalsmith-dom-transform

If you're already using metalsmith-dom-transform, you can save a little bit of overhead by accessing the code highlight transform directly:

const domTransform = require('metalsmith-dom-transform');
const codeHighlightTransform = require('metalsmith-code-highlight/transform');

metalsmith.use(domTransform({
  transforms: [
    codeHighlightTransform(options),
    // Your other transforms go here
  ]
}));

Changelog

  • 1.1.1: Update a bunch of dependencies
  • 1.1.0: Allow a selector option for overriding the default selector of code.
  • 1.0.3: Upgrade to metalsmith-dom-transform 2.0.0, no functional changes
  • 1.0.2: Upgrade to metalsmith-dom-transform 1.0.1, may cause slight change in HTML output when there is no content to highlight
  • 1.0.1: Use highlightBlock from highlight.js for the highlighting, slight change in HTML output
  • 1.0.0: Upgrade to metalsmith-dom-transform 1.0.0 (API change)
  • 0.1.1: Upgrade dependencies
  • 0.1.0: Expose transform for use with metalsmith-dom-transform

Alternatives

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].