Skip to content

Commit

Permalink
Add renderer feature. This is a updated version of #129.
Browse files Browse the repository at this point in the history
At #129, it only contains block level renderers. This patch contains
both block level and span level renderers.
Since renderer feature can do many things, I removed highlight option
and headerPrefix option.

markedjs/marked#129


git-svn-id: https://github.com/chjj/marked.git@549 de94abd1-4c94-9ff3-2ac9-ce57b7db7bff
  • Loading branch information
hsiaoming.yang committed Dec 4, 2013
1 parent 5bc5f2c commit 7272736
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 231 deletions.
5 changes: 0 additions & 5 deletions trunk/.travis.yml

This file was deleted.

73 changes: 5 additions & 68 deletions trunk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Minimal usage:

```js
console.log(marked('I am using __markdown__.'));
// Outputs: <p>I am using <strong>markdown</strong>.</p>
// Outputs: <p>I am using <i>markdown</i>.</p>
```

Example using all options:
Expand Down Expand Up @@ -86,13 +86,13 @@ 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
[node-pygementize-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) {
return hljs.highlightAuto(code).value;
highlight: function (code, lang) {
return hljs.highlightAuto(lang, code).value;
}
});
```
Expand All @@ -113,7 +113,7 @@ The programming language specified in the code block.

`callback`

Type: `Function`
Type: `String`

The callback function to call when using an async highlighter.

Expand Down Expand Up @@ -170,13 +170,6 @@ Default: `lang-`

Set the prefix for code block classes.

### 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 Expand Up @@ -267,62 +260,6 @@ disadvantage in the benchmarks above.
Along with implementing every markdown feature, marked also implements [GFM
features][gfmf].

### High level

You can customize the result with a customized renderer.

``` js
var renderer = new marked.Renderer()

renderer.header = function(text, level) {
return '<div class="h-' + level + '">' + text + '</div>'
}

var parse = function(src, options) {
options = options || {};
return marked.parser(marked.lexer(src, options), options, renderer);
}

console.log(parse('# h1'))
```

The renderer API:

```
blockcode: function(code, lang)
blockquote: function(text)
blockhtml: function(html)
header: function(text, level)
paragraph: function(text)
hrule: function()
list: function(contents, isOrdered)
listitem: function(text)
table: function(header, body)
tablerow: function(content)
tablecell: function(text, flags)
// flags: {header: false, align: 'center'}
```

### Pro level

You also have direct access to the lexer and parser if you so desire.

``` js
var tokens = marked.lexer(text, options);
console.log(marked.parser(tokens));
```

``` js
var lexer = new marked.Lexer(options);
var tokens = lexer.lex(text);
console.log(tokens);
console.log(lexer.rules);
```

``` bash
$ node
> require('marked').lexer('> i am using marked.')
Expand Down
4 changes: 2 additions & 2 deletions trunk/component.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "marked",
"version": "0.2.10",
"version": "0.2.9",
"repo": "chjj/marked",
"description": "A markdown parser built for speed",
"keywords": ["markdown", "markup", "html"],
"scripts": ["lib/marked.js"],
"main": "lib/marked.js",
"license": "MIT"
}
}
Loading

0 comments on commit 7272736

Please sign in to comment.