marked 0.2.9 → 0.3.2

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/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: node_js
2
+ node_js:
3
+ - "0.10"
4
+ - "0.8"
5
+ - "0.6"
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2013, Christopher Jeffrey (https://github.com/chjj/)
1
+ Copyright (c) 2011-2014, 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/README.md CHANGED
@@ -1,59 +1,279 @@
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
5
 
6
- ## Benchmarks
6
+ [![NPM version](https://badge.fury.io/js/marked.png)][badge]
7
7
 
8
- node v0.4.x
8
+ ## Install
9
9
 
10
10
  ``` bash
11
- $ node test --bench
12
- marked completed in 12071ms.
13
- showdown (reuse converter) completed in 27387ms.
14
- showdown (new converter) completed in 75617ms.
15
- markdown-js completed in 70069ms.
11
+ npm install marked --save
16
12
  ```
17
13
 
18
- node v0.6.x
14
+ ## Usage
19
15
 
20
- ``` bash
21
- $ node test --bench
22
- marked completed in 6448ms.
23
- marked (gfm) completed in 7357ms.
24
- marked (pedantic) completed in 6092ms.
25
- discount completed in 7314ms.
26
- showdown (reuse converter) completed in 16018ms.
27
- showdown (new converter) completed in 18234ms.
28
- markdown-js completed in 24270ms.
16
+ Minimal usage:
17
+
18
+ ```js
19
+ var marked = require('marked');
20
+ console.log(marked('I am using __markdown__.'));
21
+ // Outputs: <p>I am using <strong>markdown</strong>.</p>
29
22
  ```
30
23
 
31
- __Marked is now faster than Discount, which is written in C.__
24
+ Example setting options with default values:
32
25
 
33
- For those feeling skeptical: These benchmarks run the entire markdown test suite
34
- 1000 times. The test suite tests every feature. It doesn't cater to specific
35
- aspects.
26
+ ```js
27
+ var marked = require('marked');
28
+ marked.setOptions({
29
+ renderer: new marked.Renderer(),
30
+ gfm: true,
31
+ tables: true,
32
+ breaks: false,
33
+ pedantic: false,
34
+ sanitize: true,
35
+ smartLists: true,
36
+ smartypants: false
37
+ });
36
38
 
37
- node v0.8.x
39
+ console.log(marked('I am using __markdown__.'));
40
+ ```
38
41
 
39
- ``` bash
40
- $ node test --bench
41
- marked completed in 3411ms.
42
- marked (gfm) completed in 3727ms.
43
- marked (pedantic) completed in 3201ms.
44
- robotskirt completed in 808ms.
45
- showdown (reuse converter) completed in 11954ms.
46
- showdown (new converter) completed in 17774ms.
47
- markdown-js completed in 17191ms.
42
+ ## marked(markdownString [,options] [,callback])
43
+
44
+ ### markdownString
45
+
46
+ Type: `string`
47
+
48
+ String of markdown source to be compiled.
49
+
50
+ ### options
51
+
52
+ Type: `object`
53
+
54
+ Hash of options. Can also be set using the `marked.setOptions` method as seen
55
+ above.
56
+
57
+ ### callback
58
+
59
+ Type: `function`
60
+
61
+ Function called when the `markdownString` has been fully parsed when using
62
+ async highlighting. If the `options` argument is omitted, this can be used as
63
+ the second argument.
64
+
65
+ ## Options
66
+
67
+ ### highlight
68
+
69
+ Type: `function`
70
+
71
+ A function to highlight code blocks. The first example below uses async highlighting with
72
+ [node-pygmentize-bundled][pygmentize], and the second is a synchronous example using
73
+ [highlight.js][highlight]:
74
+
75
+ ```js
76
+ var marked = require('marked');
77
+
78
+ var markdownString = '```js\n console.log("hello"); \n```';
79
+
80
+ // Async highlighting with pygmentize-bundled
81
+ marked.setOptions({
82
+ highlight: function (code, lang, callback) {
83
+ require('pygmentize-bundled')({ lang: lang, format: 'html' }, code, function (err, result) {
84
+ callback(err, result.toString());
85
+ });
86
+ }
87
+ });
88
+
89
+ // Using async version of marked
90
+ marked(markdownString, function (err, content) {
91
+ if (err) throw err;
92
+ console.log(content);
93
+ });
94
+
95
+ // Synchronous highlighting with highlight.js
96
+ marked.setOptions({
97
+ highlight: function (code) {
98
+ return require('highlight.js').highlightAuto(code).value;
99
+ }
100
+ });
101
+
102
+ console.log(marked(markdownString));
48
103
  ```
49
104
 
50
- ## Install
105
+ #### highlight arguments
106
+
107
+ `code`
108
+
109
+ Type: `string`
110
+
111
+ The section of code to pass to the highlighter.
112
+
113
+ `lang`
114
+
115
+ Type: `string`
116
+
117
+ The programming language specified in the code block.
118
+
119
+ `callback`
120
+
121
+ Type: `function`
122
+
123
+ The callback function to call when using an async highlighter.
124
+
125
+ ### renderer
126
+
127
+ Type: `object`
128
+ Default: `new Renderer()`
129
+
130
+ An object containing functions to render tokens to HTML.
131
+
132
+ #### Overriding renderer methods
133
+
134
+ The renderer option allows you to render tokens in a custom manor. Here is an
135
+ example of overriding the default heading token rendering by adding an embedded anchor tag like on GitHub:
136
+
137
+ ```javascript
138
+ var marked = require('marked');
139
+ var renderer = new marked.Renderer();
140
+
141
+ renderer.heading = function (text, level) {
142
+ var escapedText = text.toLowerCase().replace(/[^\w]+/g, '-');
143
+
144
+ return '<h' + level + '><a name="' +
145
+ escapedText +
146
+ '" class="anchor" href="#' +
147
+ escapedText +
148
+ '"><span class="header-link"></span></a>' +
149
+ text + '</h' + level + '>';
150
+ },
151
+
152
+ console.log(marked('# heading+', { renderer: renderer }));
153
+ ```
154
+ This code will output the following HTML:
155
+ ```html
156
+ <h1>
157
+ <a name="heading-" class="anchor" href="#heading-">
158
+ <span class="header-link"></span>
159
+ </a>
160
+ heading+
161
+ </h1>
162
+ ```
163
+
164
+ #### Block level renderer methods
165
+
166
+ - code(*string* code, *string* language)
167
+ - blockquote(*string* quote)
168
+ - html(*string* html)
169
+ - heading(*string* text, *number* level)
170
+ - hr()
171
+ - list(*string* body, *boolean* ordered)
172
+ - listitem(*string* text)
173
+ - paragraph(*string* text)
174
+ - table(*string* header, *string* body)
175
+ - tablerow(*string* content)
176
+ - tablecell(*string* content, *object* flags)
177
+
178
+ `flags` has the following properties:
179
+
180
+ ```js
181
+ {
182
+ header: true || false,
183
+ align: 'center' || 'left' || 'right'
184
+ }
185
+ ```
186
+
187
+ #### Inline level renderer methods
188
+
189
+ - strong(*string* text)
190
+ - em(*string* text)
191
+ - codespan(*string* code)
192
+ - br()
193
+ - del(*string* text)
194
+ - link(*string* href, *string* title, *string* text)
195
+ - image(*string* href, *string* title, *string* text)
196
+
197
+ ### gfm
198
+
199
+ Type: `boolean`
200
+ Default: `true`
201
+
202
+ Enable [GitHub flavored markdown][gfm].
203
+
204
+ ### tables
205
+
206
+ Type: `boolean`
207
+ Default: `true`
208
+
209
+ Enable GFM [tables][tables].
210
+ This option requires the `gfm` option to be true.
211
+
212
+ ### breaks
213
+
214
+ Type: `boolean`
215
+ Default: `false`
216
+
217
+ Enable GFM [line breaks][breaks].
218
+ This option requires the `gfm` option to be true.
219
+
220
+ ### pedantic
221
+
222
+ Type: `boolean`
223
+ Default: `false`
224
+
225
+ Conform to obscure parts of `markdown.pl` as much as possible. Don't fix any of
226
+ the original markdown bugs or poor behavior.
227
+
228
+ ### sanitize
229
+
230
+ Type: `boolean`
231
+ Default: `false`
232
+
233
+ Sanitize the output. Ignore any HTML that has been input.
234
+
235
+ ### smartLists
236
+
237
+ Type: `boolean`
238
+ Default: `true`
239
+
240
+ Use smarter list behavior than the original markdown. May eventually be
241
+ default with the old behavior moved into `pedantic`.
242
+
243
+ ### smartypants
244
+
245
+ Type: `boolean`
246
+ Default: `false`
247
+
248
+ Use "smart" typograhic punctuation for things like quotes and dashes.
249
+
250
+ ## Access to lexer and parser
251
+
252
+ You also have direct access to the lexer and parser if you so desire.
253
+
254
+ ``` js
255
+ var tokens = marked.lexer(text, options);
256
+ console.log(marked.parser(tokens));
257
+ ```
258
+
259
+ ``` js
260
+ var lexer = new marked.Lexer(options);
261
+ var tokens = lexer.lex(text);
262
+ console.log(tokens);
263
+ console.log(lexer.rules);
264
+ ```
265
+
266
+ ## CLI
51
267
 
52
268
  ``` bash
53
- $ npm install marked
269
+ $ marked -o hello.html
270
+ hello world
271
+ ^D
272
+ $ cat hello.html
273
+ <p>hello world</p>
54
274
  ```
55
275
 
56
- ## Another Javascript Markdown Parser
276
+ ## Philosophy behind marked
57
277
 
58
278
  The point of marked was to create a markdown compiler where it was possible to
59
279
  frequently parse huge chunks of markdown without having to worry about
@@ -70,48 +290,30 @@ of performance, but did not in order to be exactly what you expect in terms
70
290
  of a markdown rendering. In fact, this is why marked could be considered at a
71
291
  disadvantage in the benchmarks above.
72
292
 
73
- Along with implementing every markdown feature, marked also implements
74
- [GFM features](http://github.github.com/github-flavored-markdown/).
293
+ Along with implementing every markdown feature, marked also implements [GFM
294
+ features][gfmf].
75
295
 
76
- ## Options
77
-
78
- marked has a few different switches which change behavior.
79
-
80
- - __pedantic__: Conform to obscure parts of `markdown.pl` as much as possible.
81
- Don't fix any of the original markdown bugs or poor behavior.
82
- - __gfm__: Enable github flavored markdown (enabled by default).
83
- - __sanitize__: Sanitize the output. Ignore any HTML that has been input.
84
- - __highlight__: A callback to highlight code blocks.
85
- - __tables__: Enable GFM tables. This is enabled by default. (Requires the
86
- `gfm` option in order to be enabled).
87
- - __breaks__: Enable GFM line breaks. Disabled by default.
88
- - __smartLists__: Use smarter list behavior than the original markdown.
89
- Disabled by default. May eventually be default with the old behavior
90
- moved into `pedantic`.
91
- - __langPrefix__: Set the prefix for code block classes. Defaults to `lang-`.
296
+ ## Benchmarks
92
297
 
93
- ## Usage
298
+ node v0.8.x
94
299
 
95
- ``` js
96
- // Set default options
97
- marked.setOptions({
98
- gfm: true,
99
- tables: true,
100
- breaks: false,
101
- pedantic: false,
102
- sanitize: true,
103
- smartLists: true,
104
- langPrefix: 'language-',
105
- highlight: function(code, lang) {
106
- if (lang === 'js') {
107
- return highlighter.javascript(code);
108
- }
109
- return code;
110
- }
111
- });
112
- console.log(marked('i am using __markdown__.'));
300
+ ``` bash
301
+ $ node test --bench
302
+ marked completed in 3411ms.
303
+ marked (gfm) completed in 3727ms.
304
+ marked (pedantic) completed in 3201ms.
305
+ robotskirt completed in 808ms.
306
+ showdown (reuse converter) completed in 11954ms.
307
+ showdown (new converter) completed in 17774ms.
308
+ markdown-js completed in 17191ms.
113
309
  ```
114
310
 
311
+ __Marked is now faster than Discount, which is written in C.__
312
+
313
+ 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.
314
+
315
+ ### Pro level
316
+
115
317
  You also have direct access to the lexer and parser if you so desire.
116
318
 
117
319
  ``` js
@@ -136,18 +338,49 @@ $ node
136
338
  links: {} ]
137
339
  ```
138
340
 
139
- ## CLI
341
+ ## Running Tests & Contributing
342
+
343
+ If you want to submit a pull request, make sure your changes pass the test
344
+ suite. If you're adding a new feature, be sure to add your own test.
345
+
346
+ The marked test suite is set up slightly strangely: `test/new` is for all tests
347
+ that are not part of the original markdown.pl test suite (this is where your
348
+ test should go if you make one). `test/original` is only for the original
349
+ markdown.pl tests. `test/tests` houses both types of tests after they have been
350
+ combined and moved/generated by running `node test --fix` or `marked --test
351
+ --fix`.
352
+
353
+ In other words, if you have a test to add, add it to `test/new/` and then
354
+ regenerate the tests with `node test --fix`. Commit the result. If your test
355
+ uses a certain feature, for example, maybe it assumes GFM is *not* enabled, you
356
+ can add `.nogfm` to the filename. So, `my-test.text` becomes
357
+ `my-test.nogfm.text`. You can do this with any marked option. Say you want
358
+ line breaks and smartypants enabled, your filename should be:
359
+ `my-test.breaks.smartypants.text`.
360
+
361
+ To run the tests:
140
362
 
141
363
  ``` bash
142
- $ marked -o hello.html
143
- hello world
144
- ^D
145
- $ cat hello.html
146
- <p>hello world</p>
364
+ cd marked/
365
+ node test
147
366
  ```
148
367
 
368
+ ### Contribution and License Agreement
369
+
370
+ If you contribute code to this project, you are implicitly allowing your code
371
+ to be distributed under the MIT license. You are also implicitly verifying that
372
+ all code is your original work. `</legalese>`
373
+
149
374
  ## License
150
375
 
151
- Copyright (c) 2011-2013, Christopher Jeffrey. (MIT License)
376
+ Copyright (c) 2011-2014, Christopher Jeffrey. (MIT License)
152
377
 
153
378
  See LICENSE for more info.
379
+
380
+ [gfm]: https://help.github.com/articles/github-flavored-markdown
381
+ [gfmf]: http://github.github.com/github-flavored-markdown/
382
+ [pygmentize]: https://github.com/rvagg/node-pygmentize-bundled
383
+ [highlight]: https://github.com/isagalaev/highlight.js
384
+ [badge]: http://badge.fury.io/js/marked
385
+ [tables]: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#wiki-tables
386
+ [breaks]: https://help.github.com/articles/github-flavored-markdown#newlines
package/component.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "marked",
3
+ "version": "0.3.2",
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
+ }