node package manager
Stop wasting time. Easily manage code sharing in your team. Create a free org »

metalsmith-robotskirt

metalsmith-robotskirt

A Metalsmith plugin to convert markdown files with Robotskirt, a node wrapper for Sundown.

npm Package Version MIT License Dependencies Status devDependencies Status Travis Build Status Code Climate GPA

Installation

$ npm install metalsmith-robotskirt

CLI Usage

Install via npm and then add the metalsmith-robotskirt key to your metalsmith.json with any options you want, like so:

{
  "plugins": {
    "metalsmith-robotskirt": {
      "smartypants": true,
      "extensions": {
        "tables": true
      }
    }
  }
}

Javascript Usage

Pass options to the plugin and pass it to Metalsmith with the use method:

var robotskirt = require('metalsmith-robotskirt');
 
metalsmith.use(robotskirt({
    smartypants: true,
    extensions: {
        tables: true
    }
}));

Options

All options are optional...

Defaults

var defaults = {
    extensions: {
        autolink: true,
        fenced_code: true,
        lax_spacing: true,
        no_intra_emphasis: true,
        space_headers: true,
        strikethrough: true,
        superscript: true,
        tables: true
    },
    htmlFlags: {
        skip_html: false,
        skip_style: false,
        skip_images: false,
        skip_links: false,
        safelink: false,
        toc: false,
        hard_wrap: false,
        use_xhtml: false,
        expand_tabs: false,
        escape: false
    },
    renderers: {
        blockcode: highlightCodeBlocks
    },
    smartypants: true
};

Extensions

  • autolink
    Parse links even when they are not enclosed in <> characters. Autolinks for the http, https and ftp protocols will be automatically detected. Email addresses are also handled, and http links without protocol, but starting with www.

  • fenced_code
    Parse fenced code blocks, PHP-Markdown style. Blocks delimited with 3 or more ~ or backticks will be considered as code, without the need to be indented. An optional language name may be added at the end of the opening fence for the code block

  • lax_spacing
    HTML blocks do not require to be surrounded by an empty line as in the Markdown standard.

  • no_intra_emphasis
    Do not parse emphasis inside of words. Strings such as foo_bar_baz will not generate <em> tags.

  • space_headers
    A space is always required between the hash at the beginning of a header and its name, e.g. #this is my header would not be a valid header.

  • strikethrough
    Parse strikethrough, PHP-Markdown style. Two ~ characters mark the start of a strikethrough, e.g. this is ~~good~~ bad

  • superscript
    Parse superscripts after the ^ character; contiguous superscripts are nested together, and complex values can be enclosed in parenthesis, e.g. this is the 2^(nd) time

  • tables
    Parse tables, PHP-Markdown style

HTML Flags

  • skip_html
    Do not allow any user-inputted HTML in the output.

  • skip_images
    Do not generate any <img> tags.

  • skip_links
    Do not generate any <a> tags.

  • skip_style
    Do not generate any <style> tags.

  • safelink
    Only generate links for protocols which are considered safe.

  • toc
    Add HTML anchors to each header in the output HTML, to allow linking to each section.

  • hard_wrap Insert HTML <br> tags inside on paragraphs where the origin Markdown document had newlines (by default, Markdown ignores these newlines).

  • use_xhtml Output XHTML-conformant tags.

  • expand_tabs

  • escape

Renderers

You can define your own renderers like this:

var robotskirt = require('metalsmith-robotskirt'),
    highlightjs = require('highlight.js');
 
function highlight(code, lang) {
    var validLang = lang && highlightjs.getLanguage(lang.trim()),
        highlightedCode = validLang ? highlightjs.highlight(lang, code).value : highlightjs.highlightAuto(code).value,
        langClass = validLang ? ' class="lang-' + lang + '"' : '';
    return '<pre><code' + langClass + '>' + highlightedCode + '</code></pre>';
}
 
metalsmith.use(robotskirt({
    renderers: {
        blockcode: highlight
    }
}));