chjj/marked — pull request #199 by piuccio (2013-07-17 14:15:37+00:00)
Title: Add listeners on any token

Instead of providing only a callback for code highlight, open the possibility to call a custom function for any token type.

This can be done with the configuration option `on`.

For instance
````
on : {
heading : function () {}
}
````

I'm using this to generate anchors next to headings and the table of contents automatically.

````js
var toc = [];
marked(input, {
on: {
heading : function (token, callback) {
if (token.depth <= 3) {
toc.push({
depth: token.depth,
title: token.text
});
callback(null, "" + token.text);
} else {
callback(null, token.text);
}
}
}
}, function (err, content) {
// do something with my content and TOC
});
````