A node wrapper for the awesome C markdown parsing library, sundown.
It was inspired by the Redcarpet gem released by GitHub (the bindings to Ruby).
With the arrival of version 2 after much work, Robotskirt now mirrors every feature of Redcarpet, see below.
It even has additional features!
Full documentation can be found under the
Robotskirt is distributed under the MIT license, see
Thanks to Sundown, Robotskirt is able to render markdown many times faster than other Markdown libraries.
With v2, efforts have been put to make it even lighter.
Sundown is well known for its security, speed and flexibility.
Robotskirt benefits from these features and tries to make the wrapping layer as thin as possible.
Robotskirt includes a small script to benchmark it against other popular markdown libraries.
It runs the official Markdown test suite 1000 times with each item.
Results on a Thinkpad T400 running Ubuntu 12.04 and Node 0.8.8 (currently the latest stable version):
$ node benchmark --bench robotskirt (reuse all) completed in 1354ms. robotskirt (convenience, reuse all) completed in 1353ms. robotskirt (new renderer and parser) completed in 3816ms. robotskirt (convenience, new parser) completed in 1534ms. marked completed in 3842ms. discount completed in 6025ms.6 targets benchmarked successfully.
The best way to install Robotskirt is by using NPM.
If you want to install it globally, remember to use
npm install robotskirt
Important: you don't need to have Sundown installed: Robotskirt comes bundled
with a specific Sundown version. Just install Robotskirt as any other module.
v2.7, Robotskirt uses the preferred Node-GYP to compile.
To parse Markdown, we first need a renderer. It takes the parsed Markdown,
and produces the final output (can be HTML, XHTML, ANSI, plain text, ...).
On most cases you will use Sundown's (X)HTML renderer:
var rs = require'robotskirt';var renderer = ;
Then, you make a parser that uses your renderer:
var parser = renderer;
That's it! You can now start rendering your markdown:
parserrender'Hey, *this* is `code` with ÚŦF châracters!'// '<p>Hey, <em>this</em> is <code>code</code> with ÚŦF châracters!</p>\n'
Always reuse yor parsers/renderers! As you can see in the benchmark,
making and using the same pair to render everything saves a lot of time.
If you can't reuse them (for example, because the flags are supplied by the user),
consider using the convenience way.
OK. Want to customize the output a bit? Keep reading.
new Markdown(renderer) will parse pure markdown.
However, you can have it
understand special extensions such as fenced code blocks, strikethrough, tables and more!
For example, the following will enable tables and autolinking:
var parser = renderer rsEXT_TABLES rsEXT_AUTOLINK;
You can see the full list of extensions in the docs.
Just as with extensions, you can pass certain flags to the HTML renderer.
For example, the following will use strict XHTML
and skip all the
var renderer = rsHTML_USE_XHTML rsHTML_SKIP_IMAGES;
You can see the full list of HTML flags in the docs.
Sundown is fully UTF-8 aware, both when handling and rendering.
Robotskirt will take care of the encoding and decoding tasks for you.
A renderer is just a set of functions.
Each time the parser finds a piece of Markdown it'll call the appropiate function in the renderer.
If the function is not set (
), the Markdown will be skipped or copied untouched.
Some use cases of custom renderers:
var renderer = ;if language ===//No language was provided, don't highlightreturn '<pre>' + escapeHtmlcode + '</pre>';return pygmentshighlightcode "lang": language "indent": 2;;
You can see the full list of renderer functions in the docs.
If you don't feel comfortable extending the
you can build a renderer from scratch by extending the base class:
All renderers inherit from this class. It contains all functions set to
When you don't need custom renderers at all, you can just write:
var rs = require'robotskirt';var parser = rsMarkdownstd;parserrender;
That'll build a renderer/parser pair for you.
It's faster than building them manually, because it happens natively.
You can pass extension and HTML flags to it, respectively:
var parser = rsMarkdownstdrsEXT_TABLES rsEXT_AUTOLINKrsHTML_USE_XHTML rsHTML_SKIP_IMAGES;parserrender'This becomes in XHTML!';// '<p>This becomes <a href=""></a> in XHTML!</p>\n'
Keep in mind that no other types of renderer can be chosen,
and you don't have access to the HTML renderer used.
Robotskirt includes some useful utilities. Code speaks by itself:
Houdini, the escapist
> var rs = require'robotskirt'> rshoudiniescapeHTML'<b>Some code to escape.</b> <a title="Click me!">Me & you.</a>''<b>Some code to escape.</b> <a title="Click me!">Me & you.</a>'> rshoudiniunescapeURL'Include+5%25+me%2Bin+a-query%3F+W%C3%ADth%C3%99TF%21''Include 5% me in a-query? WíthÙTF!'
Often used in conjunction with Markdown.
It makes "smart" punctuation. See more on its homepage.
> rssmartypantsHtml'And I said ---to him--- "no worries"...';'And I said —to him— “no worries”…'
Sundown implements SmartyPants with the same speed and security as usual.
> rsversionssundown<Version 1.160>> rsversionsrobotskirttoString //String formatted version'2.5.1'> console.log'Sundown is at %s. Robotskirt is at %s'rsversionssundown rsversionsrobotskirt;Sundown is at 1.160 Robotskirt is at 2.51> rsversionssundownminor16> rsversionsrobotskirt instanceof rsVersiontrue