Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A node wrapper for the awesome C markdown parser, sundown.

branch: master

This branch is 0 commits ahead and 0 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.mkd

Robotskirt

Robotskirt is a simple node binding for the sundown markdown parser. It was inspired by the Redcarpet gem released by github. Eventually Robotskirt should mirror the feature set of redcarpet, currently it doesn't support custom renderers.

Performance

Benchmarked against other popular node markdown libraries by running the entire official markdown test suit 1000 times.

$ node index.js --bench
robotskirt (reuse renderer) completed in 1794ms.
robotskirt (new renderer) completed in 1848ms.
marked completed in 5517ms.
discount completed in 5866ms.
showdown (reuse converter) completed in 13789ms.
showdown (new converter) completed in 17161ms.

Install

The best way to install robotskirt is by using npm. If you want to install it globally, remember to include the -g flag.

npm install robotskirt

If you would like to compile it, you should use node's WAF wapper. Read more about how node C/C++ addons work in the node docs.

node-waf configure build

Usage

First of all, you need to construct a new HtmlRenderer(). Then, call the markdown function passing as arguments your renderer, the markdown code to parse, and a callback to handle the result:

var rs = require('robotskirt')
  , sys = require('sys');

var renderer = new rs.HtmlRenderer();
rs.markdown(renderer, '# Hello World', function (html) {
  sys.puts(html);
});
// '<h1>Hello World</h1>\n'

For example, to read and parse a Markdown file:

var rs = require('robotskirt')
  , fs = require('fs')
  , sys = require('sys');

var renderer = new rs.HtmlRenderer();
fs.readFile('README.mkd', function (err, data) {
  rs.markdown(renderer, data, function (html) {
    sys.puts(html);
  });
});

Markdown extension flags

You can pass some flags to Sundown by passing them as an (optional) last argument:

var rs = require('robotskirt')
  , sys = require('sys');

var renderer = new rs.HtmlRenderer()
  , flags = rs.flags.EXT_FENCED_CODE + rs.flags.EXT_AUTOLINK;

rs.markdown(renderer, 'Wow, this becomes http://autolink.ed !', function (html) {
  sys.puts(html);
}, flags);

Or, to enable all supported flags, use:

var flags = ~0;

Being synchronous...

If you would like to parse your markdown synchronously you can use the markdownSync function:

var html = rs.markdownSync(new rs.HtmlRenderer(), "*sync!*").toString();

Note: keep in mind that the result is passed as a Buffer rather than a String, so you may convert it to text using toString(), as in this example.

Contributors

License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.