Detalhes do pacote

docpad-plugin-highlightjs

docpad20MIT2.6.0

Adds support for Highlight.js syntax highlighting to DocPad

docpad, docpad-plugin, highlight, syntax

readme (leia-me)

Highlight.js Plugin for DocPad

Travis CI Build Status NPM version NPM downloads Dependency Status Dev Dependency Status
Patreon donate button Open Collective donate button Flattr donate button PayPal donate button Bitcoin donate button Wishlist browse button
Slack community badge

This plugin enables Highlight.js syntax highlighting for DocPad

Install

Install the Plugin

docpad install highlightjs

Download a Stylesheet

Available stylesheets are here. You can preview some of them here.

Usage

Example inputs are here and their corresponding outputs are here. For the general gist of things, the following will suffice:

HTML

Input

<h3>Coffescript - Lang tag</h3>
<pre><code class="lang-coffeescript">
if true
    func = -&gt;
        alert "hello world"

    func()
</code></pre>

Output

<h3>Coffescript - Lang tag</h3>
<pre class="highlighted"><code class="coffeescript">
<span class="keyword">if</span> <span class="literal">true</span>
    <span class="function"><span class="title">func</span></span> = -&gt;
        alert <span class="string">"hello world"</span>

    func()
</code></pre>

Markdown

Input

### Coffeescript with fenced code

``` coffeescript
if true
    func = ->
        alert 'hello world'
    func()
```

Output

<h3>Coffeescript with fenced code</h3>
<pre class="highlighted"><code class="coffeescript"><span class="keyword">if</span> <span class="literal">true</span>
    <span class="function"><span class="title">func</span></span> = -&gt;
        alert <span class="string">'hello world'</span>
    func()</code></pre>

Configure

Language Aliases

Sometimes one of the languages you want to highlight isn't available. In which case, you'd probably want to add an alias for it to a language that is similar. To do this, you'll want to add something like the following to your docpad configuration file.

plugins:
    highlightjs:
        aliases:
            missinglanguage: 'alternativelanguage'

You can find a list of languages that are supported via the Highlight.js source tree.

Replacing Tabs

By default, we replace tabs with 4 spaces. This can be changed by changing the replaceTab configuration option:

plugins:
    highlightjs:
        replaceTab: null  # keep tabs

Transforms

You can apply transformations to code blocks before they are highlighted by using the transforms configuration option. It accepts an array of functions or arrays.

plugins:
    highlightjs:
        transforms: [
            # Remove extra indentation from the code block
            # Requires: http://balupton.com/project/bal-util
            (source, language) ->
                require('bal-util').removeIndentation(source)  if language in ['bash','coffeescript']

            # Replace "(C)" with "&copy;"
            (source) -> source.replace /\(C\)/gm, '&copy;'
        ]

Class Name

You can customise the css classname that is added by adjusting the className configuration option, defaults to highlight

plugins:
    highlightjs:
        className: 'blah'

History

Discover the release history by heading on over to the HISTORY.md file.

Contribute

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

Backers

Maintainers

These amazing people are maintaining this project:

Sponsors

No sponsors yet! Will you be the first?

Patreon donate button Open Collective donate button Flattr donate button PayPal donate button Bitcoin donate button Wishlist browse button

Contributors

These amazing people have contributed code to this project:

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

License

Unless stated otherwise all works are:

and licensed under:

changelog (log de mudanças)

History

v2.6.0 2018 June 26

  • Updated base files using boundation
  • Compiled with CoffeeScript v2
  • Updated dependencies

v2.5.0 2017 April 20

  • Updated base files

v2.4.0 2016 August 26

  • Updated dependencies
    • highlight.js ^9.6.0

v2.3.0 2014 October 19

  • Updated dependencies
    • coffee-script 1.8.0
    • highlight.js 8.3.0
    • he 0.5.0

v2.2.2 2014 June 9

v2.2.1 2014 February 15

  • Fix to have the hljs class in the code element
  • Updated dependencies
    • coffee-script 1.6.2 to 1.7.1

v2.2.0 2014 January 10

  • Updated dependencies

v2.1.9 2013 December 10

  • You can now customise the css classname that is added via the className property, defaults to highlight
  • Updated dependencies

v2.1.8 2013 October 2

  • Updated dependencies

v2.1.7 2013 June 26

  • Repackaged
  • Updated dependencies

v2.1.6 2013 April 24

  • Obey the replaceTabs configuration option

v2.1.5 2013 April 24

  • Replace tabs with spaces now that DocPad v6.31 doesn't

v2.1.4 2013 April 5

  • Updated dependencies

v2.1.3 2013 April 1

  • Updated dependencies

v2.1.2 2013 March 7

  • Repackaged
  • Updated dependencies
    • bal-util from ~1.13.13 to ~1.16.8
    • highlight.js from 7.3.x to ~7.3.0
    • ent from 0.0.4 to ~0.0.4

v2.1.1 2012 October 26

  • Fixed no highlight detection

v2.1.0 2012 October 22

  • Removed jsdom for simpler and way faster approach
  • Fixed specifying language in some instances
  • Changed sourceFilter option to the new transforms option
  • Documented the aliases option
  • Warns when language highlight definition is not found

v2.0.1 2012 October 18

  • Updated for Highlight.js 7.3.x
  • Released

v2.0.0 2012 October 12

  • Cleaned
  • Added aliases

v0.1.3 2012 September 8

v0.1.2 2012 August 25

  • Changed to the HTML5 parser because jsdom's default HTML parser occasionally failed on the provided tests
  • Better handle the default Markdown plugin's HTML output
    • Languages like Coffeescript get butchered in fenced code because it doesn't continue the code block properly

v0.1.1 2012 August 23

  • If an unrecognized language tag is used, the plugin falls back to Highlight.js's autodetection feature
  • Tests!

v0.1.0 2012 August 21