marked 0.2.6 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2012, Christopher Jeffrey (https://github.com/chjj/)
1
+ Copyright (c) 2011-2013, Christopher Jeffrey (https://github.com/chjj/)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
package/Makefile CHANGED
@@ -6,4 +6,7 @@ clean:
6
6
  @rm marked.js
7
7
  @rm marked.min.js
8
8
 
9
+ bench:
10
+ @node test --bench
11
+
9
12
  .PHONY: clean all
package/README.md CHANGED
@@ -1,7 +1,200 @@
1
1
  # marked
2
2
 
3
- A full-featured markdown parser and compiler, written in javascript.
4
- Built for speed.
3
+ > A full-featured markdown parser and compiler, written in javascript. Built
4
+ > for speed.
5
+
6
+ [![NPM version](https://badge.fury.io/js/marked.png)][badge]
7
+
8
+ ## Install
9
+
10
+ ``` bash
11
+ npm install marked --save
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ Minimal usage:
17
+
18
+ ```js
19
+ console.log(marked('I am using __markdown__.'));
20
+ // Outputs: <p>I am using <i>markdown</i>.</p>
21
+ ```
22
+
23
+ Example using all options:
24
+
25
+ ```js
26
+ // Set default options except highlight which has no default
27
+ marked.setOptions({
28
+ gfm: true,
29
+ highlight: function (code, lang, callback) {
30
+ pygmentize({ lang: lang, format: 'html' }, code, function (err, result) {
31
+ if (err) return callback(err);
32
+ callback(null, result.toString());
33
+ });
34
+ },
35
+ tables: true,
36
+ breaks: false,
37
+ pedantic: false,
38
+ sanitize: true,
39
+ smartLists: true,
40
+ smartypants: false,
41
+ langPrefix: 'lang-'
42
+ });
43
+
44
+ // Using async version of marked
45
+ marked('I am using __markdown__.', function (err, content) {
46
+ if (err) throw err;
47
+ console.log(content);
48
+ });
49
+ ```
50
+
51
+ ## marked(markdownString, [options], [callback])
52
+
53
+ ### markdownString
54
+
55
+ Type: `String`
56
+
57
+ String of markdown source to be compiled.
58
+
59
+ ### options
60
+
61
+ Type: `Object`
62
+
63
+ Hash of options. Can also be set using the `marked.setOptions` method as seen
64
+ above.
65
+
66
+ ### callback
67
+
68
+ Type: `Function`
69
+
70
+ Function called when the `markdownString` has been fully parsed when using
71
+ async highlighting. If the `options` argument is omitted, this can be used as
72
+ the second argument as seen above:
73
+
74
+ ## Options
75
+
76
+ ### gfm
77
+
78
+ Type: `Boolean`
79
+ Default: `true`
80
+
81
+ Enable [GitHub flavored markdown][gfm].
82
+
83
+ ### highlight
84
+
85
+ Type: `Function`
86
+
87
+ A function to highlight code blocks. The function takes three arguments: code,
88
+ lang, and callback. The above example uses async highlighting with
89
+ [node-pygementize-bundled][pygmentize], and here is a synchronous example using
90
+ [highlight.js][highlight] which doesn't require the callback argument:
91
+
92
+ ```js
93
+ marked.setOptions({
94
+ highlight: function (code, lang) {
95
+ return hljs.highlightAuto(lang, code).value;
96
+ }
97
+ });
98
+ ```
99
+
100
+ #### highlight arguments
101
+
102
+ `code`
103
+
104
+ Type: `String`
105
+
106
+ The section of code to pass to the highlighter.
107
+
108
+ `lang`
109
+
110
+ Type: `String`
111
+
112
+ The programming language specified in the code block.
113
+
114
+ `callback`
115
+
116
+ Type: `String`
117
+
118
+ The callback function to call when using an async highlighter.
119
+
120
+ ### tables
121
+
122
+ Type: `Boolean`
123
+ Default: `true`
124
+
125
+ Enable GFM [tables][tables].
126
+ This option requires the `gfm` option to be true.
127
+
128
+ ### breaks
129
+
130
+ Type: `Boolean`
131
+ Default: `false`
132
+
133
+ Enable GFM [line breaks][breaks].
134
+ This option requires the `gfm` option to be true.
135
+
136
+ ### pedantic
137
+
138
+ Type: `Boolean`
139
+ Default: `false`
140
+
141
+ Conform to obscure parts of `markdown.pl` as much as possible. Don't fix any of
142
+ the original markdown bugs or poor behavior.
143
+
144
+ ### sanitize
145
+
146
+ Type: `Boolean`
147
+ Default: `false`
148
+
149
+ Sanitize the output. Ignore any HTML that has been input.
150
+
151
+ ### smartLists
152
+
153
+ Type: `Boolean`
154
+ Default: `true`
155
+
156
+ Use smarter list behavior than the original markdown. May eventually be
157
+ default with the old behavior moved into `pedantic`.
158
+
159
+ ### smartypants
160
+
161
+ Type: `Boolean`
162
+ Default: `false`
163
+
164
+ Use "smart" typograhic punctuation for things like quotes and dashes.
165
+
166
+ ### langPrefix
167
+
168
+ Type: `String`
169
+ Default: `lang-`
170
+
171
+ Set the prefix for code block classes.
172
+
173
+ ## Access to lexer and parser
174
+
175
+ You also have direct access to the lexer and parser if you so desire.
176
+
177
+ ``` js
178
+ var tokens = marked.lexer(text, options);
179
+ console.log(marked.parser(tokens));
180
+ ```
181
+
182
+ ``` js
183
+ var lexer = new marked.Lexer(options);
184
+ var tokens = lexer.lex(text);
185
+ console.log(tokens);
186
+ console.log(lexer.rules);
187
+ ```
188
+
189
+ ## CLI
190
+
191
+ ``` bash
192
+ $ marked -o hello.html
193
+ hello world
194
+ ^D
195
+ $ cat hello.html
196
+ <p>hello world</p>
197
+ ```
5
198
 
6
199
  ## Benchmarks
7
200
 
@@ -34,10 +227,17 @@ For those feeling skeptical: These benchmarks run the entire markdown test suite
34
227
  1000 times. The test suite tests every feature. It doesn't cater to specific
35
228
  aspects.
36
229
 
37
- ## Install
230
+ node v0.8.x
38
231
 
39
232
  ``` bash
40
- $ npm install marked
233
+ $ node test --bench
234
+ marked completed in 3411ms.
235
+ marked (gfm) completed in 3727ms.
236
+ marked (pedantic) completed in 3201ms.
237
+ robotskirt completed in 808ms.
238
+ showdown (reuse converter) completed in 11954ms.
239
+ showdown (new converter) completed in 17774ms.
240
+ markdown-js completed in 17191ms.
41
241
  ```
42
242
 
43
243
  ## Another Javascript Markdown Parser
@@ -57,46 +257,8 @@ of performance, but did not in order to be exactly what you expect in terms
57
257
  of a markdown rendering. In fact, this is why marked could be considered at a
58
258
  disadvantage in the benchmarks above.
59
259
 
60
- Along with implementing every markdown feature, marked also implements
61
- [GFM features](http://github.github.com/github-flavored-markdown/).
62
-
63
- ## Options
64
-
65
- marked has 4 different switches which change behavior.
66
-
67
- - __pedantic__: Conform to obscure parts of `markdown.pl` as much as possible.
68
- Don't fix any of the original markdown bugs or poor behavior.
69
- - __gfm__: Enable github flavored markdown (enabled by default).
70
- - __sanitize__: Sanitize the output. Ignore any HTML that has been input.
71
- - __highlight__: A callback to highlight code blocks.
72
-
73
- None of the above are mutually exclusive/inclusive.
74
-
75
- ## Usage
76
-
77
- ``` js
78
- // Set default options
79
- marked.setOptions({
80
- gfm: true,
81
- pedantic: false,
82
- sanitize: true,
83
- // callback for code highlighter
84
- highlight: function(code, lang) {
85
- if (lang === 'js') {
86
- return javascriptHighlighter(code);
87
- }
88
- return code;
89
- }
90
- });
91
- console.log(marked('i am using __markdown__.'));
92
- ```
93
-
94
- You also have direct access to the lexer and parser if you so desire.
95
-
96
- ``` js
97
- var tokens = marked.lexer(text);
98
- console.log(marked.parser(tokens));
99
- ```
260
+ Along with implementing every markdown feature, marked also implements [GFM
261
+ features][gfmf].
100
262
 
101
263
  ``` bash
102
264
  $ node
@@ -108,18 +270,49 @@ $ node
108
270
  links: {} ]
109
271
  ```
110
272
 
111
- ## CLI
273
+ ## Running Tests & Contributing
274
+
275
+ If you want to submit a pull request, make sure your changes pass the test
276
+ suite. If you're adding a new feature, be sure to add your own test.
277
+
278
+ The marked test suite is set up slightly strangely: `test/new` is for all tests
279
+ that are not part of the original markdown.pl test suite (this is where your
280
+ test should go if you make one). `test/original` is only for the original
281
+ markdown.pl tests. `test/tests` houses both types of tests after they have been
282
+ combined and moved/generated by running `node test --fix` or `marked --test
283
+ --fix`.
284
+
285
+ In other words, if you have a test to add, add it to `test/new/` and then
286
+ regenerate the tests with `node test --fix`. Commit the result. If your test
287
+ uses a certain feature, for example, maybe it assumes GFM is *not* enabled, you
288
+ can add `.nogfm` to the filename. So, `my-test.text` becomes
289
+ `my-test.nogfm.text`. You can do this with any marked option. Say you want
290
+ line breaks and smartypants enabled, your filename should be:
291
+ `my-test.breaks.smartypants.text`.
292
+
293
+ To run the tests:
112
294
 
113
295
  ``` bash
114
- $ marked -o hello.html
115
- hello world
116
- ^D
117
- $ cat hello.html
118
- <p>hello world</p>
296
+ cd marked/
297
+ node test
119
298
  ```
120
299
 
300
+ ### Contribution and License Agreement
301
+
302
+ If you contribute code to marked, you are implicitly allowing your code to be
303
+ distributed under the MIT license. You are also implicitly verifying that all
304
+ code is your original work. `</legalese>`
305
+
121
306
  ## License
122
307
 
123
- Copyright (c) 2011-2012, Christopher Jeffrey. (MIT License)
308
+ Copyright (c) 2011-2013, Christopher Jeffrey. (MIT License)
124
309
 
125
310
  See LICENSE for more info.
311
+
312
+ [gfm]: https://help.github.com/articles/github-flavored-markdown
313
+ [gfmf]: http://github.github.com/github-flavored-markdown/
314
+ [pygmentize]: https://github.com/rvagg/node-pygmentize-bundled
315
+ [highlight]: https://github.com/isagalaev/highlight.js
316
+ [badge]: http://badge.fury.io/js/marked
317
+ [tables]: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#wiki-tables
318
+ [breaks]: https://help.github.com/articles/github-flavored-markdown#newlines
package/bin/marked CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  /**
4
4
  * Marked CLI
5
- * Copyright (c) 2011-2012, Christopher Jeffrey (MIT License)
5
+ * Copyright (c) 2011-2013, Christopher Jeffrey (MIT License)
6
6
  */
7
7
 
8
8
  var fs = require('fs')
@@ -13,7 +13,7 @@ var fs = require('fs')
13
13
  * Man Page
14
14
  */
15
15
 
16
- var help = function() {
16
+ function help() {
17
17
  var spawn = require('child_process').spawn;
18
18
 
19
19
  var options = {
@@ -26,33 +26,54 @@ var help = function() {
26
26
  spawn('man',
27
27
  [__dirname + '/../man/marked.1'],
28
28
  options);
29
- };
29
+ }
30
30
 
31
31
  /**
32
32
  * Main
33
33
  */
34
34
 
35
- var main = function(argv) {
35
+ function main(argv, callback) {
36
36
  var files = []
37
37
  , options = {}
38
- , data = ''
39
38
  , input
40
39
  , output
41
40
  , arg
42
- , tokens;
41
+ , tokens
42
+ , opt;
43
43
 
44
- var getarg = function() {
44
+ function getarg() {
45
45
  var arg = argv.shift();
46
- arg = arg.split('=');
47
- if (arg.length > 1) {
48
- argv.unshift(arg.slice(1).join('='));
46
+
47
+ if (arg.indexOf('--') === 0) {
48
+ // e.g. --opt
49
+ arg = arg.split('=');
50
+ if (arg.length > 1) {
51
+ // e.g. --opt=val
52
+ argv.unshift(arg.slice(1).join('='));
53
+ }
54
+ arg = arg[0];
55
+ } else if (arg[0] === '-') {
56
+ if (arg.length > 2) {
57
+ // e.g. -abc
58
+ argv = arg.substring(1).split('').map(function(ch) {
59
+ return '-' + ch;
60
+ }).concat(argv);
61
+ arg = argv.shift();
62
+ } else {
63
+ // e.g. -a
64
+ }
65
+ } else {
66
+ // e.g. foo
49
67
  }
50
- return arg[0];
51
- };
68
+
69
+ return arg;
70
+ }
52
71
 
53
72
  while (argv.length) {
54
73
  arg = getarg();
55
74
  switch (arg) {
75
+ case '--test':
76
+ return require('../test').main(process.argv.slice());
56
77
  case '-o':
57
78
  case '--output':
58
79
  output = argv.shift();
@@ -65,63 +86,102 @@ var main = function(argv) {
65
86
  case '--tokens':
66
87
  tokens = true;
67
88
  break;
68
- case '--gfm':
69
- options.gfm = true;
70
- break;
71
- case '--sanitize':
72
- options.sanitize = true;
73
- break;
74
- case '--pedantic':
75
- options.pedantic = true;
76
- break;
77
89
  case '-h':
78
90
  case '--help':
79
91
  return help();
80
92
  default:
81
- files.push(arg);
93
+ if (arg.indexOf('--') === 0) {
94
+ opt = camelize(arg.replace(/^--(no-)?/, ''));
95
+ if (!marked.defaults.hasOwnProperty(opt)) {
96
+ continue;
97
+ }
98
+ if (arg.indexOf('--no-') === 0) {
99
+ options[opt] = typeof marked.defaults[opt] !== 'boolean'
100
+ ? null
101
+ : false;
102
+ } else {
103
+ options[opt] = typeof marked.defaults[opt] !== 'boolean'
104
+ ? argv.shift()
105
+ : true;
106
+ }
107
+ } else {
108
+ files.push(arg);
109
+ }
82
110
  break;
83
111
  }
84
112
  }
85
113
 
86
- if (!input) {
87
- if (files.length <= 2) {
88
- var stdin = process.stdin;
89
-
90
- stdin.setEncoding('utf8');
91
- stdin.resume();
92
-
93
- stdin.on('data', function(text) {
94
- data += text;
95
- });
96
-
97
- stdin.on('end', write);
98
-
99
- return;
114
+ function getData(callback) {
115
+ if (!input) {
116
+ if (files.length <= 2) {
117
+ return getStdin(callback);
118
+ }
119
+ input = files.pop();
100
120
  }
101
- input = files.pop();
121
+ return fs.readFile(input, 'utf8', callback);
102
122
  }
103
123
 
104
- data = fs.readFileSync(input, 'utf8');
105
- write();
106
-
107
- function write() {
108
- marked.setOptions(options);
124
+ return getData(function(err, data) {
125
+ if (err) return callback(err);
109
126
 
110
127
  data = tokens
111
- ? JSON.stringify(marked.lexer(data), null, 2)
112
- : marked(data);
128
+ ? JSON.stringify(marked.lexer(data, options), null, 2)
129
+ : marked(data, options);
113
130
 
114
131
  if (!output) {
115
132
  process.stdout.write(data + '\n');
116
- } else {
117
- fs.writeFileSync(output, data);
133
+ return callback();
118
134
  }
135
+
136
+ return fs.writeFile(output, data, callback);
137
+ });
138
+ }
139
+
140
+ /**
141
+ * Helpers
142
+ */
143
+
144
+ function getStdin(callback) {
145
+ var stdin = process.stdin
146
+ , buff = '';
147
+
148
+ stdin.setEncoding('utf8');
149
+
150
+ stdin.on('data', function(data) {
151
+ buff += data;
152
+ });
153
+
154
+ stdin.on('error', function(err) {
155
+ return callback(err);
156
+ });
157
+
158
+ stdin.on('end', function() {
159
+ return callback(null, buff);
160
+ });
161
+
162
+ try {
163
+ stdin.resume();
164
+ } catch (e) {
165
+ callback(e);
119
166
  }
120
- };
167
+ }
168
+
169
+ function camelize(text) {
170
+ return text.replace(/(\w)-(\w)/g, function(_, a, b) {
171
+ return a + b.toUpperCase();
172
+ });
173
+ }
174
+
175
+ /**
176
+ * Expose / Entry Point
177
+ */
121
178
 
122
179
  if (!module.parent) {
123
180
  process.title = 'marked';
124
- main(process.argv.slice());
181
+ main(process.argv.slice(), function(err, code) {
182
+ if (err) throw err;
183
+ return process.exit(code || 0);
184
+ });
125
185
  } else {
126
186
  module.exports = main;
127
187
  }
package/component.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "marked",
3
+ "version": "0.2.9",
4
+ "repo": "chjj/marked",
5
+ "description": "A markdown parser built for speed",
6
+ "keywords": ["markdown", "markup", "html"],
7
+ "scripts": ["lib/marked.js"],
8
+ "main": "lib/marked.js",
9
+ "license": "MIT"
10
+ }