see #302. remove all obsolete features. keep things easy to revert.
This commit is contained in:
parent
bc1f59a950
commit
f9c90b0cdb
52
README.md
52
README.md
@ -23,22 +23,14 @@ console.log(marked('I am using __markdown__.'));
|
||||
Example using all options:
|
||||
|
||||
```js
|
||||
// Set default options except highlight which has no default
|
||||
marked.setOptions({
|
||||
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,
|
||||
breaks: false,
|
||||
pedantic: false,
|
||||
sanitize: true,
|
||||
smartLists: true,
|
||||
smartypants: false,
|
||||
langPrefix: 'lang-'
|
||||
});
|
||||
|
||||
// Using async version of marked
|
||||
@ -80,43 +72,6 @@ Default: `true`
|
||||
|
||||
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
|
||||
|
||||
Type: `Boolean`
|
||||
@ -220,13 +175,6 @@ You can control anything you want.
|
||||
- link(href, title, text)
|
||||
- image(href, title, text)
|
||||
|
||||
### headerPrefix
|
||||
|
||||
Type: `String`
|
||||
Default: ``
|
||||
|
||||
Set the prefix for header IDs.
|
||||
|
||||
## Access to lexer and parser
|
||||
|
||||
You also have direct access to the lexer and parser if you so desire.
|
||||
|
@ -739,28 +739,18 @@ InlineLexer.prototype.mangle = function(text) {
|
||||
|
||||
function Renderer() {}
|
||||
|
||||
Renderer.prototype.code = function(code, lang, escaped, options) {
|
||||
options = options || {};
|
||||
|
||||
if (options.highlight) {
|
||||
var out = options.highlight(code, lang);
|
||||
if (out != null && out !== code) {
|
||||
escaped = true;
|
||||
code = out;
|
||||
}
|
||||
}
|
||||
|
||||
Renderer.prototype.code = function(code, lang) {
|
||||
if (!lang) {
|
||||
return '<pre><code>'
|
||||
+ (escaped ? code : escape(code, true))
|
||||
+ escape(code, true)
|
||||
+ '\n</code></pre>';
|
||||
}
|
||||
|
||||
return '<pre><code class="'
|
||||
+ options.langPrefix
|
||||
+ 'lang-'
|
||||
+ lang
|
||||
+ '">'
|
||||
+ (escaped ? code : escape(code))
|
||||
+ escape(code)
|
||||
+ '\n</code></pre>\n';
|
||||
};
|
||||
|
||||
@ -775,9 +765,6 @@ Renderer.prototype.html = function(html) {
|
||||
Renderer.prototype.heading = function(text, level, raw, options) {
|
||||
return '<h'
|
||||
+ level
|
||||
+ ' id="'
|
||||
+ options.headerPrefix
|
||||
+ raw.toLowerCase().replace(/[^\w]+/g, '-')
|
||||
+ '>'
|
||||
+ text
|
||||
+ '</h'
|
||||
@ -946,16 +933,11 @@ Parser.prototype.tok = function() {
|
||||
case 'heading': {
|
||||
return this.renderer.heading(
|
||||
this.inline.output(this.token.text),
|
||||
this.token.depth,
|
||||
this.token.text,
|
||||
this.options
|
||||
this.token.depth
|
||||
);
|
||||
}
|
||||
case 'code': {
|
||||
return this.renderer.code(this.token.text,
|
||||
this.token.lang,
|
||||
this.token.escaped,
|
||||
this.options);
|
||||
return this.renderer.code(this.token.text, this.token.lang);
|
||||
}
|
||||
case 'table': {
|
||||
var header = ''
|
||||
@ -1134,31 +1116,7 @@ function marked(src, opt, callback) {
|
||||
: callback(null, out);
|
||||
};
|
||||
|
||||
if (!highlight || highlight.length < 3) {
|
||||
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;
|
||||
return done();
|
||||
}
|
||||
try {
|
||||
if (opt) opt = merge({}, marked.defaults, opt);
|
||||
@ -1192,10 +1150,7 @@ marked.defaults = {
|
||||
sanitize: false,
|
||||
smartLists: false,
|
||||
silent: false,
|
||||
highlight: null,
|
||||
langPrefix: 'lang-',
|
||||
smartypants: false,
|
||||
headerPrefix: '',
|
||||
renderer: new Renderer
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user