From a465627210c44b0fad848d20558cb73b2b876029 Mon Sep 17 00:00:00 2001
From: Evan Lucas Describe Foobar in more detail ' +
- 'here.\n\n
Describe Foobar II in more detail ' +
- 'here.\n\n
Describe Deprecated thingy in more ' +
- 'detail here.\n\n
' +
- 'Describe Something in more detail here.\n
' +
+ 'Describe Something in more detail here.
I am using markdown.
``` -__Marked is now faster than Discount, which is written in C.__ +Example setting options with default values: + +```js +var marked = require('marked'); +marked.setOptions({ + renderer: new marked.Renderer(), + gfm: true, + tables: true, + breaks: false, + pedantic: false, + sanitize: true, + smartLists: true, + smartypants: false +}); + +console.log(marked('I am using __markdown__.')); +``` -For those feeling skeptical: These benchmarks run the entire markdown test suite -1000 times. The test suite tests every feature. It doesn't cater to specific -aspects. +### Browser + +```html + + + + +hello world
``` -## Another javascript markdown parser +## Philosophy behind marked The point of marked was to create a markdown compiler where it was possible to frequently parse huge chunks of markdown without having to worry about @@ -58,78 +310,97 @@ of performance, but did not in order to be exactly what you expect in terms of a markdown rendering. In fact, this is why marked could be considered at a disadvantage in the benchmarks above. -Along with implementing every markdown feature, marked also implements -[GFM features](http://github.github.com/github-flavored-markdown/). +Along with implementing every markdown feature, marked also implements [GFM +features][gfmf]. -## Usage +## Benchmarks -``` js -var marked = require('marked'); -console.log(marked('i am using __markdown__.')); +node v0.8.x + +``` bash +$ node test --bench +marked completed in 3411ms. +marked (gfm) completed in 3727ms. +marked (pedantic) completed in 3201ms. +robotskirt completed in 808ms. +showdown (reuse converter) completed in 11954ms. +showdown (new converter) completed in 17774ms. +markdown-js completed in 17191ms. ``` +__Marked is now faster than Discount, which is written in C.__ + +For those feeling skeptical: These benchmarks run the entire markdown test suite 1000 times. The test suite tests every feature. It doesn't cater to specific aspects. + +### Pro level + You also have direct access to the lexer and parser if you so desire. ``` js -var tokens = marked.lexer(str); +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.') [ { type: 'blockquote_start' }, - { type: 'text', text: ' i am using marked.' }, + { type: 'paragraph', + text: 'i am using marked.' }, { type: 'blockquote_end' }, links: {} ] ``` -## CLI +## Running Tests & Contributing -``` bash -$ marked -o hello.html -hello world -^D -$ cat hello.html -hello world
-``` +If you want to submit a pull request, make sure your changes pass the test +suite. If you're adding a new feature, be sure to add your own test. -## Syntax Highlighting +The marked test suite is set up slightly strangely: `test/new` is for all tests +that are not part of the original markdown.pl test suite (this is where your +test should go if you make one). `test/original` is only for the original +markdown.pl tests. `test/tests` houses both types of tests after they have been +combined and moved/generated by running `node test --fix` or `marked --test +--fix`. -Marked has an interface that allows for a syntax highlighter to highlight code -blocks before they're output. +In other words, if you have a test to add, add it to `test/new/` and then +regenerate the tests with `node test --fix`. Commit the result. If your test +uses a certain feature, for example, maybe it assumes GFM is *not* enabled, you +can add `.nogfm` to the filename. So, `my-test.text` becomes +`my-test.nogfm.text`. You can do this with any marked option. Say you want +line breaks and smartypants enabled, your filename should be: +`my-test.breaks.smartypants.text`. -Example implementation: +To run the tests: -``` 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); +``` bash +cd marked/ +node test +``` - return text; -}; +### Contribution and License Agreement -module.exports = marked; -``` +If you contribute code to this project, you are implicitly allowing your code +to be distributed under the MIT license. You are also implicitly verifying that +all code is your original work. `` ## License -Copyright (c) 2011-2012, Christopher Jeffrey. (MIT License) +Copyright (c) 2011-2014, Christopher Jeffrey. (MIT License) See LICENSE for more info. + +[gfm]: https://help.github.com/articles/github-flavored-markdown +[gfmf]: http://github.github.com/github-flavored-markdown/ +[pygmentize]: https://github.com/rvagg/node-pygmentize-bundled +[highlight]: https://github.com/isagalaev/highlight.js +[badge]: http://badge.fury.io/js/marked +[tables]: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#wiki-tables +[breaks]: https://help.github.com/articles/github-flavored-markdown#newlines diff --git a/tools/doc/node_modules/marked/bin/marked b/tools/doc/node_modules/marked/bin/marked index 7d00504ed16..64254fc3eb2 100755 --- a/tools/doc/node_modules/marked/bin/marked +++ b/tools/doc/node_modules/marked/bin/marked @@ -2,7 +2,7 @@ /** * Marked CLI - * Copyright (c) 2011-2012, Christopher Jeffrey (MIT License) + * Copyright (c) 2011-2013, Christopher Jeffrey (MIT License) */ var fs = require('fs') @@ -13,7 +13,7 @@ var fs = require('fs') * Man Page */ -var help = function() { +function help() { var spawn = require('child_process').spawn; var options = { @@ -26,32 +26,54 @@ var help = function() { spawn('man', [__dirname + '/../man/marked.1'], options); -}; +} /** * Main */ -var main = function(argv) { +function main(argv, callback) { var files = [] - , data = '' + , options = {} , input , output , arg - , tokens; + , tokens + , opt; - var getarg = function() { + function getarg() { var arg = argv.shift(); - arg = arg.split('='); - if (arg.length > 1) { - argv.unshift(arg.slice(1).join('=')); + + if (arg.indexOf('--') === 0) { + // e.g. --opt + arg = arg.split('='); + if (arg.length > 1) { + // e.g. --opt=val + argv.unshift(arg.slice(1).join('=')); + } + arg = arg[0]; + } else if (arg[0] === '-') { + if (arg.length > 2) { + // e.g. -abc + argv = arg.substring(1).split('').map(function(ch) { + return '-' + ch; + }).concat(argv); + arg = argv.shift(); + } else { + // e.g. -a + } + } else { + // e.g. foo } - return arg[0]; - }; + + return arg; + } while (argv.length) { arg = getarg(); switch (arg) { + case '--test': + return require('../test').main(process.argv.slice()); case '-o': case '--output': output = argv.shift(); @@ -68,48 +90,98 @@ var main = function(argv) { case '--help': return help(); default: - files.push(arg); + if (arg.indexOf('--') === 0) { + opt = camelize(arg.replace(/^--(no-)?/, '')); + if (!marked.defaults.hasOwnProperty(opt)) { + continue; + } + if (arg.indexOf('--no-') === 0) { + options[opt] = typeof marked.defaults[opt] !== 'boolean' + ? null + : false; + } else { + options[opt] = typeof marked.defaults[opt] !== 'boolean' + ? argv.shift() + : true; + } + } else { + files.push(arg); + } break; } } - if (!input) { - if (files.length <= 2) { - var stdin = process.stdin; - - stdin.setEncoding('utf8'); - stdin.resume(); - - stdin.on('data', function(text) { - data += text; - }); - - stdin.on('end', write); - - return; + function getData(callback) { + if (!input) { + if (files.length <= 2) { + return getStdin(callback); + } + input = files.pop(); } - input = files.pop(); + return fs.readFile(input, 'utf8', callback); } - data = fs.readFileSync(input, 'utf8'); - write(); + return getData(function(err, data) { + if (err) return callback(err); - function write() { data = tokens - ? JSON.stringify(marked.lexer(data), null, 2) - : marked(data); + ? JSON.stringify(marked.lexer(data, options), null, 2) + : marked(data, options); if (!output) { process.stdout.write(data + '\n'); - } else { - fs.writeFileSync(output, data); + return callback(); } + + return fs.writeFile(output, data, callback); + }); +} + +/** + * Helpers + */ + +function getStdin(callback) { + var stdin = process.stdin + , buff = ''; + + stdin.setEncoding('utf8'); + + stdin.on('data', function(data) { + buff += data; + }); + + stdin.on('error', function(err) { + return callback(err); + }); + + stdin.on('end', function() { + return callback(null, buff); + }); + + try { + stdin.resume(); + } catch (e) { + callback(e); } -}; +} + +function camelize(text) { + return text.replace(/(\w)-(\w)/g, function(_, a, b) { + return a + b.toUpperCase(); + }); +} + +/** + * Expose / Entry Point + */ if (!module.parent) { process.title = 'marked'; - main(process.argv.slice()); + main(process.argv.slice(), function(err, code) { + if (err) throw err; + return process.exit(code || 0); + }); } else { module.exports = main; } diff --git a/tools/doc/node_modules/marked/bower.json b/tools/doc/node_modules/marked/bower.json new file mode 100644 index 00000000000..a2a8187759f --- /dev/null +++ b/tools/doc/node_modules/marked/bower.json @@ -0,0 +1,24 @@ +{ + "name": "marked", + "version": "0.3.4", + "homepage": "https://github.com/chjj/marked", + "authors": [ + "Christopher Jeffreyitem1
+ +text
item1
+text
++world
++world
+
item1
+ +text
item1
+text
++world
++world
+
+world
world
code>var a = 1;
<div>hello</div>
+ +<span>hello</span>
+``` + +``` bash +$ marked +hello +
+``` + +- - - + +See: https://github.com/evilstreak/markdown-js/issues/27 + +``` bash +$ markdown.js +[](/link) +^D + +``` + +``` bash +$ marked +[](/link) +^D + +``` + +- - - + +See: https://github.com/evilstreak/markdown-js/issues/24 + +``` bash +$ markdown.js +> a + +> b + +> c +^D ++``` + +``` bash +$ marked +> a + +> b + +> c +^D +a
bundefined> c
+a + +
+b + +
+``` + +- - - + +``` bash +$ markdown.pl +* hello + * world + how + + are + you + + * today +* hi +^D +c +
hello
+ +are +you
+ +hello
+world +how
+are +you
+today
+'
- + escape(cap[2], true)
- + '';
+ out += this.renderer.codespan(escape(cap[2], true));
continue;
}
// br
- if (cap = inline.br.exec(src)) {
+ if (cap = this.rules.br.exec(src)) {
+ src = src.substring(cap[0].length);
+ out += this.renderer.br();
+ continue;
+ }
+
+ // del (gfm)
+ if (cap = this.rules.del.exec(src)) {
src = src.substring(cap[0].length);
- out += ''
+ + (escaped ? code : escape(code, true))
+ + '\n';
+ }
+
+ return ''
+ + (escaped ? code : escape(code, true))
+ + '\n\n';
+};
+
+Renderer.prototype.blockquote = function(quote) {
+ return '\n' + quote + '\n'; +}; + +Renderer.prototype.html = function(html) { + return html; +}; + +Renderer.prototype.heading = function(text, level, raw) { + return '
' + text + '
\n'; +}; + +Renderer.prototype.table = function(header, body) { + return '' + text + '';
+};
+
+Renderer.prototype.br = function() {
+ return this.options.xhtml ? ''
- + (token.escaped
- ? token.text
- : escape(token.text, true))
- + '\n';
+ return this.renderer.code(this.token.text,
+ this.token.lang,
+ this.token.escaped);
+ }
+ case 'table': {
+ var header = ''
+ , body = ''
+ , i
+ , row
+ , cell
+ , flags
+ , j;
+
+ // header
+ cell = '';
+ for (i = 0; i < this.token.header.length; i++) {
+ flags = { header: true, align: this.token.align[i] };
+ cell += this.renderer.tablecell(
+ this.inline.output(this.token.header[i]),
+ { header: true, align: this.token.align[i] }
+ );
+ }
+ header += this.renderer.tablerow(cell);
+
+ for (i = 0; i < this.token.cells.length; i++) {
+ row = this.token.cells[i];
+
+ cell = '';
+ for (j = 0; j < row.length; j++) {
+ cell += this.renderer.tablecell(
+ this.inline.output(row[j]),
+ { header: false, align: this.token.align[j] }
+ );
+ }
+
+ body += this.renderer.tablerow(cell);
+ }
+ return this.renderer.table(header, body);
}
case 'blockquote_start': {
var body = '';
- while (next().type !== 'blockquote_end') {
- body += tok();
+ while (this.next().type !== 'blockquote_end') {
+ body += this.tok();
}
- return '\n' - + body - + '\n'; + return this.renderer.blockquote(body); } case 'list_start': { - var type = token.ordered ? 'ol' : 'ul' - , body = ''; + var body = '' + , ordered = this.token.ordered; - while (next().type !== 'list_end') { - body += tok(); + while (this.next().type !== 'list_end') { + body += this.tok(); } - return '<' - + type - + '>\n' - + body - + '' - + type - + '>\n'; + return this.renderer.list(body, ordered); } case 'list_item_start': { var body = ''; - while (next().type !== 'list_item_end') { - body += token.type === 'text' - ? parseText() - : tok(); + while (this.next().type !== 'list_item_end') { + body += this.token.type === 'text' + ? this.parseText() + : this.tok(); } - return '
' - + inline.lexer(token.text) - + '
\n'; + return this.renderer.paragraph(this.inline.output(this.token.text)); } case 'text': { - return '' - + parseText() - + '
\n'; + return this.renderer.paragraph(this.parseText()); } } }; -var parseText = function() { - var body = token.text - , top; - - while ((top = tokens[tokens.length-1]) - && top.type === 'text') { - body += '\n' + next().text; - } - - return inline.lexer(body); -}; - -var parse = function(src) { - tokens = src.reverse(); - - var out = ''; - while (next()) { - out += tok(); - } - - tokens = null; - token = null; - - return out; -}; - /** * Helpers */ -var escape = function(html, encode) { +function escape(html, encode) { return html .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, '''); -}; +} -var mangle = function(text) { - var out = '' - , l = text.length - , i = 0 - , ch; +function unescape(html) { + return html.replace(/&([#\w]+);/g, function(_, n) { + n = n.toLowerCase(); + if (n === 'colon') return ':'; + if (n.charAt(0) === '#') { + return n.charAt(1) === 'x' + ? String.fromCharCode(parseInt(n.substring(2), 16)) + : String.fromCharCode(+n.substring(1)); + } + return ''; + }); +} - for (; i < l; i++) { - ch = text.charCodeAt(i); - if (Math.random() > 0.5) { - ch = 'x' + ch.toString(16); +function replace(regex, opt) { + regex = regex.source; + opt = opt || ''; + return function self(name, val) { + if (!name) return new RegExp(regex, opt); + val = val.source || val; + val = val.replace(/(^|[^\[])\^/g, '$1'); + regex = regex.replace(name, val); + return self; + }; +} + +function noop() {} +noop.exec = noop; + +function merge(obj) { + var i = 1 + , target + , key; + + for (; i < arguments.length; i++) { + target = arguments[i]; + for (key in target) { + if (Object.prototype.hasOwnProperty.call(target, key)) { + obj[key] = target[key]; + } } - out += '' + ch + ';'; } - return out; -}; + return obj; +} -function tag() { - var tag = '(?!(?:' - + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code' - + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo' - + '|span|br|wbr|ins|del|img)\\b)\\w+'; - return tag; +/** + * Marked + */ + +function marked(src, opt, callback) { + if (callback || typeof opt === 'function') { + if (!callback) { + callback = opt; + opt = null; + } + + opt = merge({}, marked.defaults, opt || {}); + + var highlight = opt.highlight + , tokens + , pending + , i = 0; + + try { + tokens = Lexer.lex(src, opt) + } catch (e) { + return callback(e); + } + + pending = tokens.length; + + var done = function(err) { + if (err) { + opt.highlight = highlight; + return callback(err); + } + + var out; + + try { + out = Parser.parse(tokens, opt); + } catch (e) { + err = e; + } + + opt.highlight = highlight; + + return err + ? callback(err) + : 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 (err) return done(err); + if (code == null || code === token.text) { + return --pending || done(); + } + token.text = code; + token.escaped = true; + --pending || done(); + }); + })(tokens[i]); + } + + return; + } + try { + if (opt) opt = merge({}, marked.defaults, opt); + return Parser.parse(Lexer.lex(src, opt), opt); + } catch (e) { + e.message += '\nPlease report this to https://github.com/chjj/marked.'; + if ((opt || marked.defaults).silent) { + return 'An error occured:
' + + escape(e.message + '', true) + + ''; + } + throw e; + } } /** - * Expose + * Options */ -var marked = function(src) { - return parse(block.lexer(src)); +marked.options = +marked.setOptions = function(opt) { + merge(marked.defaults, opt); + return marked; }; -marked.parser = parse; -marked.lexer = block.lexer; +marked.defaults = { + gfm: true, + tables: true, + breaks: false, + pedantic: false, + sanitize: false, + sanitizer: null, + mangle: true, + smartLists: false, + silent: false, + highlight: null, + langPrefix: 'lang-', + smartypants: false, + headerPrefix: '', + renderer: new Renderer, + xhtml: false +}; + +/** + * Expose + */ + +marked.Parser = Parser; +marked.parser = Parser.parse; + +marked.Renderer = Renderer; + +marked.Lexer = Lexer; +marked.lexer = Lexer.lex; + +marked.InlineLexer = InlineLexer; +marked.inlineLexer = InlineLexer.output; marked.parse = marked; -if (typeof module !== 'undefined') { +if (typeof module !== 'undefined' && typeof exports === 'object') { module.exports = marked; +} else if (typeof define === 'function' && define.amd) { + define(function() { return marked; }); } else { this.marked = marked; } -}).call(this); +}).call(function() { + return this || (typeof window !== 'undefined' ? window : global); +}()); diff --git a/tools/doc/node_modules/marked/man/marked.1 b/tools/doc/node_modules/marked/man/marked.1 index 214533390ce..b9bdc8c2123 100644 --- a/tools/doc/node_modules/marked/man/marked.1 +++ b/tools/doc/node_modules/marked/man/marked.1 @@ -1,39 +1,91 @@ .ds q \N'34' -.TH marked 1 +.TH marked 1 "2014-01-31" "v0.3.1" "marked.js" + .SH NAME marked \- a javascript markdown parser + .SH SYNOPSIS -.nf -.B marked [\-o output] [\-i input] [\-th] -.fi +.B marked +[\-o \fI