## The `marked` function ```js marked(markdownString [,options] [,callback]) ``` |Argument |Type |Notes | |:---------------------|:------------|:----------------------------------------------------------------------------------------------------| |markdownString |`string` |String of markdown source to be compiled. | |options|`object`|Hash of options. Can also use `marked.setOptions`. | |callback |`function` |Called when `markdownString` has been parsed. Can be used as second argument if no `options` present.| ### Alternative using reference ```js // Create reference instance var myMarked = require('marked'); // Set options // `highlight` example uses `highlight.js` myMarked.setOptions({ renderer: new myMarked.Renderer(), highlight: function(code) { return require('highlight.js').highlightAuto(code).value; }, pedantic: false, gfm: true, tables: true, breaks: false, sanitize: false, smartLists: true, smartypants: false, xhtml: false }); // Compile console.log(myMarked('I am using __markdown__.')); ```
` block. Useful for syntax highlighting.|
|mangle |`boolean` |`true` |??? |??? |
|pedantic |`boolean` |`false` |??? |If true, conform to the original `markdown.pl` as much as possible. Don't fix original markdown bugs or behavior. Turns off and overrides `gfm`.|
|renderer |`object` |`new Renderer()`|???|An object containing functions to render tokens to HTML. See [extensibility](USING_PRO.md) for more details.|
|sanitize |`boolean` |`false` |??? |If true, sanitize the HTML passed into `markdownString` with the `sanitizer` function.|
|sanitizer |`function`|`null` |??? |A function to sanitize the HTML passed into `markdownString`.|
|silent |`boolean` |`false` |??? |??? |
|smartLists |`boolean` |`false` |??? |If true, use smarter list behavior than those found in `markdown.pl`.|
|smartypants |`boolean` |`false` |??? |If true, use "smart" typographic punctuation for things like quotes and dashes.|
|tables |`boolean` |`true` |??? |If true and `gfm` is true, use [GFM Tables extension](https://github.github.com/gfm/#tables-extension-).|
|xhtml |`boolean` |`false` |??? |If true, emit self-closing HTML tags for void elements (<br/>, <img/>, etc.) with a "/" as required by XHTML.|
Asynchronous highlighting
Unlike `highlight.js` the `pygmentize.js` library uses asynchronous highlighting. This example demonstrates that marked is agnostic when it comes to the highlighter you use.
```js
myMarked.setOptions({
highlight: function(code, lang, callback) {
require('pygmentize-bundled') ({ lang: lang, format: 'html' }, code, function (err, result) {
callback(err, result.toString());
});
}
});
console.log(myMarked(markdownString));
```
In both examples, `code` is a `string` representing the section of code to pass to the highlighter. In this example, `lang` is a `string` informing the highlighter what programming lnaguage to use for the `code` and `callback` is the `function` the asynchronous highlighter will call once complete.