Update module marked. Customize renderer to remove id from heading.
PR-URL: https://github.com/nodejs/node/pull/6396
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Along with implementing every markdown feature, marked also implements [GFM
features][gfmf].
## Usage
## Benchmarks
``` js
var marked = require('marked');
console.log(marked('i am using __markdown__.'));
node v0.8.x
``` bash
$ node test --bench
marked completed in 3411ms.
marked (gfm) completed in 3727ms.
marked (pedantic) completed in 3201ms.
robotskirt completed in 808ms.
showdown (reuse converter) completed in 11954ms.
showdown (new converter) completed in 17774ms.
markdown-js completed in 17191ms.
```
__Marked is now faster than Discount, which is written in C.__
For those feeling skeptical: These benchmarks run the entire markdown test suite 1000 times. The test suite tests every feature. It doesn't cater to specific aspects.
### Pro level
You also have direct access to the lexer and parser if you so desire.
``` js
var tokens = marked.lexer(str);
var tokens = marked.lexer(text, options);
console.log(marked.parser(tokens));
```
``` js
var lexer = new marked.Lexer(options);
var tokens = lexer.lex(text);
console.log(tokens);
console.log(lexer.rules);
```
``` bash
$ node
> require('marked').lexer('> i am using marked.')
[ { type: 'blockquote_start' },
{ type: 'text', text: ' i am using marked.' },
{ type: 'paragraph',
text: 'i am using marked.' },
{ type: 'blockquote_end' },
links: {} ]
```
## CLI
## Running Tests & Contributing
``` bash
$ marked -o hello.html
hello world
^D
$ cat hello.html
<p>hello world</p>
```
If you want to submit a pull request, make sure your changes pass the test
suite. If you're adding a new feature, be sure to add your own test.
## Syntax Highlighting
The marked test suite is set up slightly strangely: `test/new` is for all tests
that are not part of the original markdown.pl test suite (this is where your
test should go if you make one). `test/original` is only for the original
markdown.pl tests. `test/tests` houses both types of tests after they have been
combined and moved/generated by running `node test --fix` or `marked --test
--fix`.
Marked has an interface that allows for a syntax highlighter to highlight code
blocks before they're output.
In other words, if you have a test to add, add it to `test/new/` and then
regenerate the tests with `node test --fix`. Commit the result. If your test
uses a certain feature, for example, maybe it assumes GFM is *not* enabled, you
can add `.nogfm` to the filename. So, `my-test.text` becomes
`my-test.nogfm.text`. You can do this with any marked option. Say you want
line breaks and smartypants enabled, your filename should be:
`my-test.breaks.smartypants.text`.
Example implementation:
To run the tests:
``` js
var highlight = require('my-syntax-highlighter')
, marked_ = require('marked');
var marked = function(text) {
var tokens = marked_.lexer(text)
, l = tokens.length
, i = 0
, token;
for (; i <l;i++){
token = tokens[i];
if (token.type === 'code') {
token.text = highlight(token.text, token.lang);
// marked should not escape this
token.escaped = true;
}
}
text = marked_.parser(tokens);
``` bash
cd marked/
node test
```
return text;
};
### Contribution and License Agreement
module.exports = marked;
```
If you contribute code to this project, you are implicitly allowing your code
to be distributed under the MIT license. You are also implicitly verifying that
all code is your original work. `</legalese>`
## License
Copyright (c) 2011-2012, Christopher Jeffrey. (MIT License)
Copyright (c) 2011-2014, Christopher Jeffrey. (MIT License)