Merge pull request #1176 from vsemozhetbyt/doc-using-pro-tokens-exhaustion

Document mutability of tokens argument in parser
This commit is contained in:
Steven 2018-04-01 21:53:11 -04:00 committed by GitHub
commit 9a52de7a2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -119,3 +119,39 @@ $ node
{ type: 'blockquote_end' },
links: {} ]
```
The Lexers build an array of tokens, which will be passed to their respective
Parsers. The Parsers process each token in the token arrays,
which are removed from the array of tokens:
``` js
const marked = require('marked');
const md = `
# heading
[link][1]
[1]: #heading "heading"
`;
const tokens = marked.lexer(md);
console.log(tokens);
const html = marked.parser(tokens);
console.log(html);
console.log(tokens);
```
``` bash
[ { type: 'heading', depth: 1, text: 'heading' },
{ type: 'paragraph', text: ' [link][1]' },
{ type: 'space' },
links: { '1': { href: '#heading', title: 'heading' } } ]
<h1 id="heading">heading</h1>
<p> <a href="#heading" title="heading">link</a></p>
[ links: { '1': { href: '#heading', title: 'heading' } } ]
```