Skip to content

Commit

Permalink
see #302. remove all obsolete features. keep things easy to revert.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Dec 4, 2013
1 parent bc1f59a commit f9c90b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 104 deletions.
52 changes: 0 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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.
Expand Down
59 changes: 7 additions & 52 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
};

Expand All @@ -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'
Expand Down Expand Up @@ -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 = ''
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1192,10 +1150,7 @@ marked.defaults = {
sanitize: false,
smartLists: false,
silent: false,
highlight: null,
langPrefix: 'lang-',
smartypants: false,
headerPrefix: '',
renderer: new Renderer
};

Expand Down

0 comments on commit f9c90b0

Please sign in to comment.