see #302. remove all obsolete features. keep things easy to revert.

This commit is contained in:
Christopher Jeffrey 2013-12-04 06:21:50 -06:00
parent bc1f59a950
commit f9c90b0cdb
2 changed files with 7 additions and 104 deletions

View File

@ -23,22 +23,14 @@ console.log(marked('I am using __markdown__.'));
Example using all options: Example using all options:
```js ```js
// Set default options except highlight which has no default
marked.setOptions({ marked.setOptions({
gfm: true, gfm: true,
highlight: function (code, lang, callback) {
pygmentize({ lang: lang, format: 'html' }, code, function (err, result) {
if (err) return callback(err);
callback(null, result.toString());
});
},
tables: true, tables: true,
breaks: false, breaks: false,
pedantic: false, pedantic: false,
sanitize: true, sanitize: true,
smartLists: true, smartLists: true,
smartypants: false, smartypants: false,
langPrefix: 'lang-'
}); });
// Using async version of marked // Using async version of marked
@ -80,43 +72,6 @@ Default: `true`
Enable [GitHub flavored markdown][gfm]. Enable [GitHub flavored markdown][gfm].
### highlight
Type: `Function`
A function to highlight code blocks. The function takes three arguments: code,
lang, and callback. The above example uses async highlighting with
[node-pygmentize-bundled][pygmentize], and here is a synchronous example using
[highlight.js][highlight] which doesn't require the callback argument:
```js
marked.setOptions({
highlight: function(code, lang) {
return hljs.highlightAuto(lang, code).value;
}
});
```
#### highlight arguments
`code`
Type: `String`
The section of code to pass to the highlighter.
`lang`
Type: `String`
The programming language specified in the code block.
`callback`
Type: `Function`
The callback function to call when using an async highlighter.
### tables ### tables
Type: `Boolean` Type: `Boolean`
@ -220,13 +175,6 @@ You can control anything you want.
- link(href, title, text) - link(href, title, text)
- image(href, title, text) - image(href, title, text)
### headerPrefix
Type: `String`
Default: ``
Set the prefix for header IDs.
## Access to lexer and parser ## Access to lexer and parser
You also have direct access to the lexer and parser if you so desire. You also have direct access to the lexer and parser if you so desire.

View File

@ -739,28 +739,18 @@ InlineLexer.prototype.mangle = function(text) {
function Renderer() {} function Renderer() {}
Renderer.prototype.code = function(code, lang, escaped, options) { Renderer.prototype.code = function(code, lang) {
options = options || {};
if (options.highlight) {
var out = options.highlight(code, lang);
if (out != null && out !== code) {
escaped = true;
code = out;
}
}
if (!lang) { if (!lang) {
return '<pre><code>' return '<pre><code>'
+ (escaped ? code : escape(code, true)) + escape(code, true)
+ '\n</code></pre>'; + '\n</code></pre>';
} }
return '<pre><code class="' return '<pre><code class="'
+ options.langPrefix + 'lang-'
+ lang + lang
+ '">' + '">'
+ (escaped ? code : escape(code)) + escape(code)
+ '\n</code></pre>\n'; + '\n</code></pre>\n';
}; };
@ -775,9 +765,6 @@ Renderer.prototype.html = function(html) {
Renderer.prototype.heading = function(text, level, raw, options) { Renderer.prototype.heading = function(text, level, raw, options) {
return '<h' return '<h'
+ level + level
+ ' id="'
+ options.headerPrefix
+ raw.toLowerCase().replace(/[^\w]+/g, '-')
+ '>' + '>'
+ text + text
+ '</h' + '</h'
@ -946,16 +933,11 @@ Parser.prototype.tok = function() {
case 'heading': { case 'heading': {
return this.renderer.heading( return this.renderer.heading(
this.inline.output(this.token.text), this.inline.output(this.token.text),
this.token.depth, this.token.depth
this.token.text,
this.options
); );
} }
case 'code': { case 'code': {
return this.renderer.code(this.token.text, return this.renderer.code(this.token.text, this.token.lang);
this.token.lang,
this.token.escaped,
this.options);
} }
case 'table': { case 'table': {
var header = '' var header = ''
@ -1134,31 +1116,7 @@ function marked(src, opt, callback) {
: callback(null, out); : callback(null, out);
}; };
if (!highlight || highlight.length < 3) { return done();
return done();
}
delete opt.highlight;
if (!pending) return done();
for (; i < tokens.length; i++) {
(function(token) {
if (token.type !== 'code') {
return --pending || done();
}
return highlight(token.text, token.lang, function(err, code) {
if (code == null || code === token.text) {
return --pending || done();
}
token.text = code;
token.escaped = true;
--pending || done();
});
})(tokens[i]);
}
return;
} }
try { try {
if (opt) opt = merge({}, marked.defaults, opt); if (opt) opt = merge({}, marked.defaults, opt);
@ -1192,10 +1150,7 @@ marked.defaults = {
sanitize: false, sanitize: false,
smartLists: false, smartLists: false,
silent: false, silent: false,
highlight: null,
langPrefix: 'lang-',
smartypants: false, smartypants: false,
headerPrefix: '',
renderer: new Renderer renderer: new Renderer
}; };