Giter Site home page Giter Site logo

metalsmith-code-highlight's Introduction

No longer maintained

This is no longer maintained, code is archived and available for forking though.

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.