Comparing version 0.2.3 to 0.2.4-1
@@ -28,3 +28,3 @@ /** | ||
block.list = replace(block.list) | ||
('bullet', /(?:[*+-](?!(?: *[-*]){2,})|\d+\.)/) | ||
('bullet', /(?:[*+-](?!(?: *[-*]){2,})|\d+\.) /) | ||
(); | ||
@@ -535,5 +535,15 @@ | ||
case 'code': { | ||
if (options.highlight) { | ||
token.code = options.highlight(token.text, token.lang); | ||
if (token.code != null && token.code !== token.text) { | ||
token.escaped = true; | ||
token.text = token.code; | ||
} | ||
} | ||
if (!token.escaped) { | ||
token.text = escape(token.text, true); | ||
} | ||
return '<pre><code' | ||
+ (token.lang | ||
? ' class="' | ||
? ' class="lang-' | ||
+ token.lang | ||
@@ -543,5 +553,3 @@ + '"' | ||
+ '>' | ||
+ (token.escaped | ||
? token.text | ||
: escape(token.text, true)) | ||
+ token.text | ||
+ '</code></pre>\n'; | ||
@@ -744,2 +752,3 @@ } | ||
setOptions(opt); | ||
return marked; | ||
}; | ||
@@ -750,3 +759,4 @@ | ||
pedantic: false, | ||
sanitize: false | ||
sanitize: false, | ||
highlight: null | ||
}); | ||
@@ -776,2 +786,4 @@ | ||
}).call(this); | ||
}).call(function() { | ||
return this || (typeof window !== 'undefined' ? window : global); | ||
}()); |
@@ -5,3 +5,3 @@ { | ||
"author": "Christopher Jeffrey", | ||
"version": "0.2.3", | ||
"version": "0.2.4-1", | ||
"main": "./lib/marked.js", | ||
@@ -8,0 +8,0 @@ "bin": "./bin/marked", |
# marked | ||
A full-featured markdown parser and compiler. | ||
A full-featured markdown parser and compiler, written in javascript. | ||
Built for speed. | ||
@@ -37,4 +37,2 @@ | ||
Benchmarks for other engines to come (?). | ||
## Install | ||
@@ -46,3 +44,3 @@ | ||
## Another javascript markdown parser | ||
## Another Javascript Markdown Parser | ||
@@ -69,8 +67,9 @@ The point of marked was to create a markdown compiler where it was possible to | ||
marked has 3 different switches which change behavior. | ||
marked has 4 different switches which change behavior. | ||
- __pedantic__: Conform to obscure parts of `markdown.pl` as much as possible. | ||
Don't fix any of the original markdown bugs or poor behavior. | ||
- __gfm__: Enabled github flavored markdown (default for backward compatibility). | ||
- __gfm__: Enable github flavored markdown (enabled by default). | ||
- __sanitize__: Sanitize the output. Ignore any HTML that has been input. | ||
- __highlight__: A callback to highlight code blocks. | ||
@@ -82,7 +81,14 @@ None of the above are mutually exclusive/inclusive. | ||
``` js | ||
// set default options | ||
// Set default options | ||
marked.setOptions({ | ||
gfm: true, | ||
pedantic: false, | ||
sanitize: true | ||
sanitize: true, | ||
// callback for code highlighter | ||
highlight: function(code, lang) { | ||
if (lang === 'js') { | ||
return javascriptHighlighter(code); | ||
} | ||
return code; | ||
} | ||
}); | ||
@@ -95,3 +101,3 @@ console.log(marked('i am using __markdown__.')); | ||
``` js | ||
var tokens = marked.lexer(str); | ||
var tokens = marked.lexer(text); | ||
console.log(marked.parser(tokens)); | ||
@@ -104,3 +110,4 @@ ``` | ||
[ { type: 'blockquote_start' }, | ||
{ type: 'text', text: ' i am using marked.' }, | ||
{ type: 'paragraph', | ||
text: 'i am using marked.' }, | ||
{ type: 'blockquote_end' }, | ||
@@ -120,36 +127,2 @@ links: {} ] | ||
## Syntax Highlighting | ||
Marked has an interface that allows for a syntax highlighter to highlight code | ||
blocks before they're output. | ||
Example implementation: | ||
``` js | ||
var highlight = require('my-syntax-highlighter') | ||
, marked_ = require('marked'); | ||
var marked = function(text) { | ||
var tokens = marked_.lexer(text) | ||
, l = tokens.length | ||
, i = 0 | ||
, token; | ||
for (; i < l; i++) { | ||
token = tokens[i]; | ||
if (token.type === 'code') { | ||
token.text = highlight(token.text, token.lang); | ||
// marked should not escape this | ||
token.escaped = true; | ||
} | ||
} | ||
text = marked_.parser(tokens); | ||
return text; | ||
}; | ||
module.exports = marked; | ||
``` | ||
## License | ||
@@ -156,0 +129,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
671
24230
126