Robotskirt
Robotskirt is a Node.JS wrapper for the Sundown library.
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 doc
folder.
Robotskirt is distributed under the MIT license, see LICENSE
.
Performance
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[1] robotskirt completed in 1354ms.[2] robotskirt completed in 1353ms.[3] robotskirt completed in 3816ms.[4] robotskirt completed in 1534ms.[5] marked completed in 3842ms.[6] discount completed in 6025ms.6 targets benchmarked successfully.
Install
The best way to install Robotskirt is by using NPM.
If you want to install it globally, remember to use sudo
and -g
.
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.
Starting with v2.7
, Robotskirt uses the preferred Node-GYP to compile.
Getting started
Currently there are two ways of using Robotskirt:
normal and convenience.
We recommend you to learn both (hey, it's just two classes!) and see the examples.
The Normal Way
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 = ;var renderer = ;
Then, you make a parser that uses your renderer:
var parser = renderer;
That's it! You can now start rendering your markdown:
parser// '<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.
Using markdown extensions
Just using 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.
HTML rendering flags
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 <image>
tags:
var renderer = rsHTML_USE_XHTML rsHTML_SKIP_IMAGES;
You can see the full list of HTML flags in the docs.
UTF handling
Sundown is fully UTF-8 aware, both when handling and rendering.
Robotskirt will take care of the encoding and decoding tasks for you.
Custom renderers!
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 (undefined
), the Markdown will be skipped or copied untouched.
Some use cases of custom renderers:
Highlighting code blocks
var renderer = ;renderer { if language === undefined //No language was provided, don't highlight return '<pre>' + + '</pre>'; return pygments;};
You can see the full list of renderer functions in the docs.
Renderer from scratch
If you don't feel comfortable extending the HtmlRenderer
class,
you can build a renderer from scratch by extending the base class: Renderer
.
All renderers inherit from this class. It contains all functions set to undefined
.
The Convenience Way
When you don't need custom renderers at all, you can just write:
var rs = ;var parser = rsMarkdown;parser;
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 = rsMarkdown;parser;// '<p>This becomes <a href="http://autolink.ed">http://autolink.ed</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.
Examples
TODO
Other utilities
Robotskirt includes some useful utilities. Code speaks by itself:
Houdini, the escapist
> var rs => rshoudini'<b>Some code to escape.</b> <a title="Click me!">Me & you.</a>'> rshoudini'Include 5% me in a-query? WíthÙTF!'
SmartyPants
Often used in conjunction with Markdown.
It makes "smart" punctuation. See more on its homepage.
> rs;'And I said —to him— “no worries”…'
Sundown implements SmartyPants with the same speed and security as usual.
Sundown's Autolink-er
//COMING SOON!
Version stuff
> rsversionssundown<Version 1160>> rsversionsrobotskirt //String formatted version'2.5.1'> console;Sundown is at 1160 Robotskirt is at 251> rsversionssundownminor16> rsversionsrobotskirt instanceof rsVersiontrue