marked 0.3.13 → 0.3.17
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/.eslintrc.json +27 -0
- package/.travis.yml +13 -2
- package/AUTHORS.md +45 -0
- package/CONTRIBUTING.md +95 -0
- package/LICENSE.md +43 -0
- package/README.md +50 -370
- package/RELEASE.md +24 -0
- package/USAGE_ADVANCED.md +71 -0
- package/USAGE_EXTENSIBILITY.md +136 -0
- package/lib/marked.js +128 -127
- package/marked.min.js +1 -1
- package/package.json +17 -5
- package/LICENSE +0 -19
package/README.md
CHANGED
|
@@ -1,52 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
<ul>
|
|
2
|
+
<li><a href="#marked">About</a></li>
|
|
3
|
+
<li><a href="#install">Installation</a></li>
|
|
4
|
+
<li><a href="#usage">Usage</a></li>
|
|
5
|
+
<li><a href="#specifications">Supported Markdown specifications</a></li>
|
|
6
|
+
<li><a href="#security">Security</a></li>
|
|
7
|
+
<li><a href="#contributing">Contributing</a></li>
|
|
8
|
+
<li><a href="#authors">Authors</a></li>
|
|
9
|
+
<li><a href="#license">License</a></li>
|
|
10
|
+
</ul>
|
|
2
11
|
|
|
3
|
-
>
|
|
4
|
-
> for speed.
|
|
12
|
+
<h2 id="marked">Marked</h2>
|
|
5
13
|
|
|
6
|
-
|
|
14
|
+
Marked is
|
|
7
15
|
|
|
8
|
-
|
|
16
|
+
1. built for speed.<sup>*</sup>
|
|
17
|
+
2. a low-level markdown compiler that allows frequent parsing of large chunks of markdown without caching or blocking for long periods of time.<sup>**</sup>
|
|
18
|
+
3. light-weight while implementing all markdown features from the supported flavors & specifications.<sup>***</sup>
|
|
19
|
+
4. available as a command line interface (CLI) and running in client- or server-side JavaScript projects.
|
|
9
20
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
or if you want to use the `marked` CLI tool (not necessary when using npm run-scripts):
|
|
15
|
-
|
|
16
|
-
``` bash
|
|
17
|
-
npm install -g marked
|
|
18
|
-
```
|
|
21
|
+
<p><small><sup>*</sup> Still working on metrics for comparative analysis and definition.</small><br>
|
|
22
|
+
<small><sup>**</sup> As few dependencies as possible.</small><br>
|
|
23
|
+
<small><sup>***</sup> Strict compliance could result in slower processing when running comparative benchmarking.</small></p>
|
|
19
24
|
|
|
20
|
-
|
|
25
|
+
<h2 id="installation">Installation</h2>
|
|
21
26
|
|
|
22
|
-
|
|
27
|
+
**CLI:** `npm install -g marked`
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
var marked = require('marked');
|
|
26
|
-
console.log(marked('I am using __markdown__.'));
|
|
27
|
-
// Outputs: <p>I am using <strong>markdown</strong>.</p>
|
|
28
|
-
```
|
|
29
|
+
**In-browser:** `npm install marked --save`
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
<h2 id="usage">Usage</h2>
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
var marked = require('marked');
|
|
34
|
-
marked.setOptions({
|
|
35
|
-
renderer: new marked.Renderer(),
|
|
36
|
-
gfm: true,
|
|
37
|
-
tables: true,
|
|
38
|
-
breaks: false,
|
|
39
|
-
pedantic: false,
|
|
40
|
-
sanitize: false,
|
|
41
|
-
smartLists: true,
|
|
42
|
-
smartypants: false,
|
|
43
|
-
xhtml: false
|
|
44
|
-
});
|
|
33
|
+
**CLI**
|
|
45
34
|
|
|
46
|
-
|
|
35
|
+
``` bash
|
|
36
|
+
$ marked -o hello.html
|
|
37
|
+
hello world
|
|
38
|
+
^D
|
|
39
|
+
$ cat hello.html
|
|
40
|
+
<p>hello world</p>
|
|
47
41
|
```
|
|
48
42
|
|
|
49
|
-
|
|
43
|
+
**Browser**
|
|
50
44
|
|
|
51
45
|
```html
|
|
52
46
|
<!doctype html>
|
|
@@ -54,7 +48,7 @@ console.log(marked('I am using __markdown__.'));
|
|
|
54
48
|
<head>
|
|
55
49
|
<meta charset="utf-8"/>
|
|
56
50
|
<title>Marked in the browser</title>
|
|
57
|
-
<script src="
|
|
51
|
+
<script src="/path/to/marked.min.js"></script>
|
|
58
52
|
</head>
|
|
59
53
|
<body>
|
|
60
54
|
<div id="content"></div>
|
|
@@ -66,352 +60,38 @@ console.log(marked('I am using __markdown__.'));
|
|
|
66
60
|
</html>
|
|
67
61
|
```
|
|
68
62
|
|
|
69
|
-
## marked(markdownString [,options] [,callback])
|
|
70
|
-
|
|
71
|
-
### markdownString
|
|
72
|
-
|
|
73
|
-
Type: `string`
|
|
74
|
-
|
|
75
|
-
String of markdown source to be compiled.
|
|
76
|
-
|
|
77
|
-
### options
|
|
78
|
-
|
|
79
|
-
Type: `object`
|
|
80
|
-
|
|
81
|
-
Hash of options. Can also be set using the `marked.setOptions` method as seen
|
|
82
|
-
above.
|
|
83
|
-
|
|
84
|
-
### callback
|
|
85
|
-
|
|
86
|
-
Type: `function`
|
|
87
|
-
|
|
88
|
-
Function called when the `markdownString` has been fully parsed when using
|
|
89
|
-
async highlighting. If the `options` argument is omitted, this can be used as
|
|
90
|
-
the second argument.
|
|
91
|
-
|
|
92
|
-
## Options
|
|
93
|
-
|
|
94
|
-
### highlight
|
|
95
|
-
|
|
96
|
-
Type: `function`
|
|
97
|
-
|
|
98
|
-
A function to highlight code blocks. The first example below uses async highlighting with
|
|
99
|
-
[node-pygmentize-bundled][pygmentize], and the second is a synchronous example using
|
|
100
|
-
[highlight.js][highlight]:
|
|
101
|
-
|
|
102
|
-
```js
|
|
103
|
-
var marked = require('marked');
|
|
104
|
-
|
|
105
|
-
var markdownString = '```js\n console.log("hello"); \n```';
|
|
106
|
-
|
|
107
|
-
// Async highlighting with pygmentize-bundled
|
|
108
|
-
marked.setOptions({
|
|
109
|
-
highlight: function (code, lang, callback) {
|
|
110
|
-
require('pygmentize-bundled')({ lang: lang, format: 'html' }, code, function (err, result) {
|
|
111
|
-
callback(err, result.toString());
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
// Using async version of marked
|
|
117
|
-
marked(markdownString, function (err, content) {
|
|
118
|
-
if (err) throw err;
|
|
119
|
-
console.log(content);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
// Synchronous highlighting with highlight.js
|
|
123
|
-
marked.setOptions({
|
|
124
|
-
highlight: function (code) {
|
|
125
|
-
return require('highlight.js').highlightAuto(code).value;
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
console.log(marked(markdownString));
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
#### highlight arguments
|
|
133
|
-
|
|
134
|
-
`code`
|
|
135
|
-
|
|
136
|
-
Type: `string`
|
|
137
|
-
|
|
138
|
-
The section of code to pass to the highlighter.
|
|
139
|
-
|
|
140
|
-
`lang`
|
|
141
|
-
|
|
142
|
-
Type: `string`
|
|
143
|
-
|
|
144
|
-
The programming language specified in the code block.
|
|
145
|
-
|
|
146
|
-
`callback`
|
|
147
|
-
|
|
148
|
-
Type: `function`
|
|
149
|
-
|
|
150
|
-
The callback function to call when using an async highlighter.
|
|
151
|
-
|
|
152
|
-
### renderer
|
|
153
|
-
|
|
154
|
-
Type: `object`
|
|
155
|
-
Default: `new Renderer()`
|
|
156
|
-
|
|
157
|
-
An object containing functions to render tokens to HTML.
|
|
158
|
-
|
|
159
|
-
#### Overriding renderer methods
|
|
160
|
-
|
|
161
|
-
The renderer option allows you to render tokens in a custom manner. Here is an
|
|
162
|
-
example of overriding the default heading token rendering by adding an embedded anchor tag like on GitHub:
|
|
163
|
-
|
|
164
|
-
```javascript
|
|
165
|
-
var marked = require('marked');
|
|
166
|
-
var renderer = new marked.Renderer();
|
|
167
|
-
|
|
168
|
-
renderer.heading = function (text, level) {
|
|
169
|
-
var escapedText = text.toLowerCase().replace(/[^\w]+/g, '-');
|
|
170
|
-
|
|
171
|
-
return '<h' + level + '><a name="' +
|
|
172
|
-
escapedText +
|
|
173
|
-
'" class="anchor" href="#' +
|
|
174
|
-
escapedText +
|
|
175
|
-
'"><span class="header-link"></span></a>' +
|
|
176
|
-
text + '</h' + level + '>';
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
console.log(marked('# heading+', { renderer: renderer }));
|
|
180
|
-
```
|
|
181
|
-
This code will output the following HTML:
|
|
182
|
-
```html
|
|
183
|
-
<h1>
|
|
184
|
-
<a name="heading-" class="anchor" href="#heading-">
|
|
185
|
-
<span class="header-link"></span>
|
|
186
|
-
</a>
|
|
187
|
-
heading+
|
|
188
|
-
</h1>
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
#### Block level renderer methods
|
|
192
|
-
|
|
193
|
-
- code(*string* code, *string* language)
|
|
194
|
-
- blockquote(*string* quote)
|
|
195
|
-
- html(*string* html)
|
|
196
|
-
- heading(*string* text, *number* level)
|
|
197
|
-
- hr()
|
|
198
|
-
- list(*string* body, *boolean* ordered)
|
|
199
|
-
- listitem(*string* text)
|
|
200
|
-
- paragraph(*string* text)
|
|
201
|
-
- table(*string* header, *string* body)
|
|
202
|
-
- tablerow(*string* content)
|
|
203
|
-
- tablecell(*string* content, *object* flags)
|
|
204
|
-
|
|
205
|
-
`flags` has the following properties:
|
|
206
|
-
|
|
207
|
-
```js
|
|
208
|
-
{
|
|
209
|
-
header: true || false,
|
|
210
|
-
align: 'center' || 'left' || 'right'
|
|
211
|
-
}
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
#### Inline level renderer methods
|
|
215
|
-
|
|
216
|
-
- strong(*string* text)
|
|
217
|
-
- em(*string* text)
|
|
218
|
-
- codespan(*string* code)
|
|
219
|
-
- br()
|
|
220
|
-
- del(*string* text)
|
|
221
|
-
- link(*string* href, *string* title, *string* text)
|
|
222
|
-
- image(*string* href, *string* title, *string* text)
|
|
223
|
-
- text(*string* text)
|
|
224
|
-
|
|
225
|
-
### gfm
|
|
226
|
-
|
|
227
|
-
Type: `boolean`
|
|
228
|
-
Default: `true`
|
|
229
|
-
|
|
230
|
-
Enable [GitHub flavored markdown][gfm].
|
|
231
|
-
|
|
232
|
-
### tables
|
|
233
|
-
|
|
234
|
-
Type: `boolean`
|
|
235
|
-
Default: `true`
|
|
236
|
-
|
|
237
|
-
Enable GFM [tables][tables].
|
|
238
|
-
This option requires the `gfm` option to be true.
|
|
239
|
-
|
|
240
|
-
### breaks
|
|
241
|
-
|
|
242
|
-
Type: `boolean`
|
|
243
|
-
Default: `false`
|
|
244
|
-
|
|
245
|
-
Enable GFM [line breaks][breaks].
|
|
246
|
-
This option requires the `gfm` option to be true.
|
|
247
|
-
|
|
248
|
-
### pedantic
|
|
249
|
-
|
|
250
|
-
Type: `boolean`
|
|
251
|
-
Default: `false`
|
|
252
|
-
|
|
253
|
-
Conform to obscure parts of `markdown.pl` as much as possible. Don't fix any of
|
|
254
|
-
the original markdown bugs or poor behavior.
|
|
255
|
-
|
|
256
|
-
### sanitize
|
|
257
|
-
|
|
258
|
-
Type: `boolean`
|
|
259
|
-
Default: `false`
|
|
260
|
-
|
|
261
|
-
Sanitize the output. Ignore any HTML that has been input.
|
|
262
|
-
|
|
263
|
-
### smartLists
|
|
264
|
-
|
|
265
|
-
Type: `boolean`
|
|
266
|
-
Default: `true`
|
|
267
|
-
|
|
268
|
-
Use smarter list behavior than the original markdown. May eventually be
|
|
269
|
-
default with the old behavior moved into `pedantic`.
|
|
270
|
-
|
|
271
|
-
### smartypants
|
|
272
|
-
|
|
273
|
-
Type: `boolean`
|
|
274
|
-
Default: `false`
|
|
275
|
-
|
|
276
|
-
Use "smart" typographic punctuation for things like quotes and dashes.
|
|
277
|
-
|
|
278
|
-
### xhtml
|
|
279
|
-
|
|
280
|
-
Type: `boolean`
|
|
281
|
-
Default: `false`
|
|
282
|
-
|
|
283
|
-
Self-close the tags for void elements (<br/>, <img/>, etc.) with a "/" as required by XHTML.
|
|
284
|
-
|
|
285
|
-
## Access to lexer and parser
|
|
286
|
-
|
|
287
|
-
You also have direct access to the lexer and parser if you so desire.
|
|
288
|
-
|
|
289
|
-
``` js
|
|
290
|
-
var tokens = marked.lexer(text, options);
|
|
291
|
-
console.log(marked.parser(tokens));
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
``` js
|
|
295
|
-
var lexer = new marked.Lexer(options);
|
|
296
|
-
var tokens = lexer.lex(text);
|
|
297
|
-
console.log(tokens);
|
|
298
|
-
console.log(lexer.rules);
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
## CLI
|
|
302
|
-
|
|
303
|
-
``` bash
|
|
304
|
-
$ marked -o hello.html
|
|
305
|
-
hello world
|
|
306
|
-
^D
|
|
307
|
-
$ cat hello.html
|
|
308
|
-
<p>hello world</p>
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
## Philosophy behind marked
|
|
312
|
-
|
|
313
|
-
The point of marked was to create a markdown compiler where it was possible to
|
|
314
|
-
frequently parse huge chunks of markdown without having to worry about
|
|
315
|
-
caching the compiled output somehow...or blocking for an unnecessarily long time.
|
|
316
|
-
|
|
317
|
-
marked is very concise and still implements all markdown features. It is also
|
|
318
|
-
now fully compatible with the client-side.
|
|
319
|
-
|
|
320
|
-
marked more or less passes the official markdown test suite in its
|
|
321
|
-
entirety. This is important because a surprising number of markdown compilers
|
|
322
|
-
cannot pass more than a few tests. It was very difficult to get marked as
|
|
323
|
-
compliant as it is. It could have cut corners in several areas for the sake
|
|
324
|
-
of performance, but did not in order to be exactly what you expect in terms
|
|
325
|
-
of a markdown rendering. In fact, this is why marked could be considered at a
|
|
326
|
-
disadvantage in the benchmarks.
|
|
327
|
-
|
|
328
|
-
Along with implementing every markdown feature, marked also implements [GFM
|
|
329
|
-
features][gfmf].
|
|
330
|
-
|
|
331
|
-
## Benchmarks
|
|
332
|
-
|
|
333
|
-
node v8.9.4
|
|
334
|
-
|
|
335
|
-
``` bash
|
|
336
|
-
$ npm run bench
|
|
337
|
-
marked completed in 3408ms.
|
|
338
|
-
marked (gfm) completed in 3465ms.
|
|
339
|
-
marked (pedantic) completed in 3032ms.
|
|
340
|
-
showdown (reuse converter) completed in 21444ms.
|
|
341
|
-
showdown (new converter) completed in 23058ms.
|
|
342
|
-
markdown-it completed in 3364ms.
|
|
343
|
-
markdown.js completed in 12090ms.
|
|
344
|
-
```
|
|
345
|
-
|
|
346
|
-
### Pro level
|
|
347
63
|
|
|
348
|
-
|
|
64
|
+
Marked offers [advanced configurations](https://github.com/markedjs/marked/blob/master/USAGE_ADVANCED.md) and [extensibility](https://github.com/markedjs/marked/blob/master/USAGE_EXTENSIBILITY.md) as well.
|
|
349
65
|
|
|
350
|
-
|
|
351
|
-
var tokens = marked.lexer(text, options);
|
|
352
|
-
console.log(marked.parser(tokens));
|
|
353
|
-
```
|
|
66
|
+
<h2 id="specifications">Supported Markdown specifications</h2>
|
|
354
67
|
|
|
355
|
-
|
|
356
|
-
var lexer = new marked.Lexer(options);
|
|
357
|
-
var tokens = lexer.lex(text);
|
|
358
|
-
console.log(tokens);
|
|
359
|
-
console.log(lexer.rules);
|
|
360
|
-
```
|
|
68
|
+
We actively support the features of the following [Markdown flavors](https://github.com/commonmark/CommonMark/wiki/Markdown-Flavors).
|
|
361
69
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
[
|
|
366
|
-
|
|
367
|
-
text: 'i am using marked.' },
|
|
368
|
-
{ type: 'blockquote_end' },
|
|
369
|
-
links: {} ]
|
|
370
|
-
```
|
|
70
|
+
|Flavor |Version |
|
|
71
|
+
|:----------------------------------------------------------|:----------|
|
|
72
|
+
|The original markdown.pl |-- |
|
|
73
|
+
|[CommonMark](http://spec.commonmark.org/0.28/) |0.28 |
|
|
74
|
+
|[GitHub Flavored Markdown](https://github.github.com/gfm/) |0.28 |
|
|
371
75
|
|
|
372
|
-
|
|
76
|
+
By supporting the above Markdown flavors, it's possible that Marked can help you use other flavors as well; however, these are not actively supported by the community.
|
|
373
77
|
|
|
374
|
-
|
|
375
|
-
suite. If you're adding a new feature, be sure to add your own test.
|
|
78
|
+
<h2 id="security">Security</h2>
|
|
376
79
|
|
|
377
|
-
The
|
|
378
|
-
that are not part of the original markdown.pl test suite (this is where your
|
|
379
|
-
test should go if you make one). `test/original` is only for the original
|
|
380
|
-
markdown.pl tests.
|
|
80
|
+
The only completely secure system is the one that doesn't exist in the first place. Having said that, we take the security of Marked very seriously; however, none of us are necessarily security experts, so to speak. Therefore, if you find something, [say something](https://github.com/markedjs/marked/issues), or, better yet, fix the thing! :)
|
|
381
81
|
|
|
382
|
-
|
|
383
|
-
uses a certain feature, for example, maybe it assumes GFM is *not* enabled, you
|
|
384
|
-
can add [front-matter](https://www.npmjs.com/package/front-matter) to the top of
|
|
385
|
-
your `.md` file
|
|
82
|
+
<h2 id="contributing">Contributing</h2>
|
|
386
83
|
|
|
387
|
-
|
|
388
|
-
---
|
|
389
|
-
gfm: false
|
|
390
|
-
---
|
|
391
|
-
```
|
|
84
|
+
The marked community enjoys a spirit of collaboration and contribution from all comers. Whether you're just getting started with Markdown, JavaScript, and Marked or you're a veteran with it all figured out, we're here to help each other improve as professionals while helping Marked improve technically. Please see our [contributing documentation](https://github.com/markedjs/marked/blob/master/CONTRIBUTING.md) for more details.
|
|
392
85
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
``` bash
|
|
396
|
-
npm run test
|
|
397
|
-
```
|
|
86
|
+
For our Contribution License Agreement, see our [license](https://github.com/markedjs/marked/blob/master/LICENSE.md).
|
|
398
87
|
|
|
399
|
-
|
|
88
|
+
<h2 id="authors">Authors</h2>
|
|
400
89
|
|
|
401
|
-
|
|
402
|
-
to be distributed under the MIT license. You are also implicitly verifying that
|
|
403
|
-
all code is your original work. `</legalese>`
|
|
90
|
+
For list of credited authors and contributors, please see our [authors page](https://github.com/markedjs/marked/blob/master/AUTHORS.md).
|
|
404
91
|
|
|
405
|
-
|
|
92
|
+
<h2 id="license">License</h2>
|
|
406
93
|
|
|
407
94
|
Copyright (c) 2011-2018, Christopher Jeffrey. (MIT License)
|
|
408
95
|
|
|
409
|
-
See LICENSE for more
|
|
96
|
+
See [license](https://github.com/markedjs/marked/blob/master/LICENSE.md) for more details.
|
|
410
97
|
|
|
411
|
-
[gfm]: https://help.github.com/articles/github-flavored-markdown
|
|
412
|
-
[gfmf]: http://github.github.com/github-flavored-markdown/
|
|
413
|
-
[pygmentize]: https://github.com/rvagg/node-pygmentize-bundled
|
|
414
|
-
[highlight]: https://github.com/isagalaev/highlight.js
|
|
415
|
-
[badge]: http://badge.fury.io/js/marked
|
|
416
|
-
[tables]: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#wiki-tables
|
|
417
|
-
[breaks]: https://help.github.com/articles/github-flavored-markdown#newlines
|
package/RELEASE.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Releasing Marked
|
|
2
|
+
|
|
3
|
+
- [ ] See [contributing](https://github.com/markedjs/marked/blob/master/CONTRIBUTING.md)
|
|
4
|
+
- [ ] Create release branch from `master` (`release-x.y.z`)
|
|
5
|
+
- [ ] Submit PR with minimal name: Release x.y.z
|
|
6
|
+
- [ ] Complete PR checklists
|
|
7
|
+
|
|
8
|
+
## Overall strategy
|
|
9
|
+
|
|
10
|
+
**Master is always shippable:** We try to merge PRs in such a way that `master` is the only branch to really be concerned about *and* `master` can always be released. This allows smoother flow between new fetures, bug fixes, and so on. (Almost a continuous deployment setup, without automation.)
|
|
11
|
+
|
|
12
|
+
## Versioning
|
|
13
|
+
|
|
14
|
+
We follow [semantic versioning](https://semver.org) where the following sequence is true `[major].[minor].[patch]`; therefore, consider the following implications of the release you are preparing:
|
|
15
|
+
|
|
16
|
+
1. **Major:** There is at least one change not deemed backward compatible.
|
|
17
|
+
2. **Minor:** There is at least one new feature added to the release.
|
|
18
|
+
3. **Patch:** No breaking changes, no new features.
|
|
19
|
+
|
|
20
|
+
What to expect while Marked is a zero-major (0.x.y):
|
|
21
|
+
|
|
22
|
+
1. The major will remain at zero; thereby, alerting consumers to the potentially volatile nature of the package.
|
|
23
|
+
2. The minor will tend to be more analagous to a `major` release. For example, we plan to release `0.4.0` once we have fixed most, if not all, known issues related to the CommonMark and GFM specifications because the architecture changes planned during `0.4.0` will most likely introduce breaking changes.
|
|
24
|
+
3. The patch will tend to be more analagous to a `minor` release.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
## The `marked` function
|
|
2
|
+
|
|
3
|
+
```js
|
|
4
|
+
marked(markdownString [,options] [,callback])
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
|Argument |Type |Notes |
|
|
8
|
+
|:---------------------|:------------|:----------------------------------------------------------------------------------------------------|
|
|
9
|
+
|markdownString |`string` |String of markdown source to be compiled. |
|
|
10
|
+
|<a href="#options">options</a>|`object`|Hash of options. Can also use `marked.setOptions`. |
|
|
11
|
+
|callback |`function` |Called when `markdownString` has been parsed. Can be used as second argument if no `options` present.|
|
|
12
|
+
|
|
13
|
+
### Alternative using reference
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
// Create reference instance
|
|
17
|
+
var myMarked = require('marked');
|
|
18
|
+
|
|
19
|
+
// Set options
|
|
20
|
+
// `highlight` example uses `highlight.js`
|
|
21
|
+
myMarked.setOptions({
|
|
22
|
+
renderer: new marked.Renderer(),
|
|
23
|
+
highlight: function(code) {
|
|
24
|
+
return require('highlight.js').highlightAuto(code).value;
|
|
25
|
+
},
|
|
26
|
+
pedantic: false,
|
|
27
|
+
gfm: true,
|
|
28
|
+
tables: true,
|
|
29
|
+
breaks: false,
|
|
30
|
+
sanitize: false,
|
|
31
|
+
smartLists: true,
|
|
32
|
+
smartypants: false,
|
|
33
|
+
xhtml: false
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Compile
|
|
37
|
+
console.log(myMarked('I am using __markdown__.'));
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
<h2 id="options">Options</h2>
|
|
41
|
+
|
|
42
|
+
|Member |Type |Notes |
|
|
43
|
+
|:----------|:---------|:----------------------------------------------------------------------------------------------------------------------------|
|
|
44
|
+
|highlight |`function`|A function to highlight code blocks. See also: <a href="#highlight">Asynchronous highlighting</a>. |
|
|
45
|
+
|renderer |`object` |An object containing functions to render tokens to HTML. See [extensibility](https://github.com/markedjs/marked/blob/master/USAGE_EXTENSIBILITY.md) for more details. Default: `new Renderer()`|
|
|
46
|
+
|pedantic |`boolean` |Conform to obscure parts of `markdown.pl` as much as possible. Don't fix original markdown bugs or behavior. Default: `false`|
|
|
47
|
+
|gfm |`boolean` |Use approved [GitHub Flavored Markdown (GFM) specification](https://github.github.com/gfm/). |
|
|
48
|
+
|tables |`boolean` |Use [GFM Tables extension](https://github.github.com/gfm/#tables-extension-). Requires `gfm` be `true`. |
|
|
49
|
+
|breaks |`boolean` |Use GFM [hard](https://github.github.com/gfm/#hard-line-breaks) and [soft](https://github.github.com/gfm/#soft-line-breaks) line breaks. Requires `gfm` be `true`. Default: `false`|
|
|
50
|
+
|sanitize |`boolean` |Ignore HTML passed into `markdownString` (sanitize the input). Default: `false` |
|
|
51
|
+
|smartlists |`boolean` |Use smarter list behavior than those found in `markdown.pl`. Default: `true` |
|
|
52
|
+
|smartypants|`boolean` |Use "smart" typographic punctuation for things like quotes and dashes. |
|
|
53
|
+
|xhtml |`boolean` |Self-close the tags for void elements (<br/>, <img/>, etc.) with a "/" as required by XHTML. Default: `false` |
|
|
54
|
+
|
|
55
|
+
<h2 id="highlight">Asynchronous highlighting</h2>
|
|
56
|
+
|
|
57
|
+
Unlike `highlight.js` the `pygmatize.js` library uses asynchronous highlighting. This example demonstrates that marked is agnostic when it comes to the highlighter you use.
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
myMarked.setOptions({
|
|
61
|
+
highlight: function(code, lang, callback) {
|
|
62
|
+
require('pygmentize-bundled') ({ lang: lang, format: 'html' }, code, function (err, result) {
|
|
63
|
+
callback(err, result.toString());
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
console.log(myMarked(markdownString));
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
In both examples, `code` is a `string` representing the section of code to pass to the highlighter. In this example, `lang` is a `string` informing the highlighter what programming lnaguage to use for the `code` and `callback` is the `function` the asynchronous highlighter will call once complete.
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
## Extending Marked
|
|
2
|
+
|
|
3
|
+
To champion the single-reponsibility and open/closed prinicples, we have tried to make it relatively painless to extend marked. If you are looking to add custom functionality, this is the place to start.
|
|
4
|
+
|
|
5
|
+
<ul>
|
|
6
|
+
<li><a href="#renderer">The renderer</a></li>
|
|
7
|
+
<li><a href="#lexer">The lexer</a></li>
|
|
8
|
+
<li><a href="#parser">The parser</a></li>
|
|
9
|
+
</ul>
|
|
10
|
+
|
|
11
|
+
<h2 id="renderer">The renderer</h2>
|
|
12
|
+
|
|
13
|
+
The renderer is...
|
|
14
|
+
|
|
15
|
+
**Example:** Overriding default heading token by adding an embedded anchor tag like on GitHub.
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
// Create reference instance
|
|
19
|
+
var myMarked = require('marked');
|
|
20
|
+
|
|
21
|
+
// Get reference
|
|
22
|
+
var renderer = new myMarked.Renderer();
|
|
23
|
+
|
|
24
|
+
// Override function
|
|
25
|
+
renderer.heading = function (text, level) {
|
|
26
|
+
var escapedText = text.toLowerCase().replace(/[^\w]+/g, '-');
|
|
27
|
+
|
|
28
|
+
return `<h${level}>
|
|
29
|
+
<a name="'${escapedText}'" class="anchor" href="#${escapedText}">
|
|
30
|
+
<span class="header-link"></span>
|
|
31
|
+
</a>
|
|
32
|
+
${text}
|
|
33
|
+
</h${level}>`;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Run marked
|
|
37
|
+
console.log(marked('# heading+', { renderer: renderer }));
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Output:**
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<h1>
|
|
44
|
+
<a name="heading-" class="anchor" href="#heading-">
|
|
45
|
+
<span class="header-link"></span>
|
|
46
|
+
</a>
|
|
47
|
+
heading+
|
|
48
|
+
</h1>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Block level renderer methods
|
|
52
|
+
|
|
53
|
+
- code(*string* code, *string* language)
|
|
54
|
+
- blockquote(*string* quote)
|
|
55
|
+
- html(*string* html)
|
|
56
|
+
- heading(*string* text, *number* level)
|
|
57
|
+
- hr()
|
|
58
|
+
- list(*string* body, *boolean* ordered)
|
|
59
|
+
- listitem(*string* text)
|
|
60
|
+
- paragraph(*string* text)
|
|
61
|
+
- table(*string* header, *string* body)
|
|
62
|
+
- tablerow(*string* content)
|
|
63
|
+
- tablecell(*string* content, *object* flags)
|
|
64
|
+
|
|
65
|
+
`flags` has the following properties:
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
{
|
|
69
|
+
header: true || false,
|
|
70
|
+
align: 'center' || 'left' || 'right'
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Inline level renderer methods
|
|
75
|
+
|
|
76
|
+
- strong(*string* text)
|
|
77
|
+
- em(*string* text)
|
|
78
|
+
- codespan(*string* code)
|
|
79
|
+
- br()
|
|
80
|
+
- del(*string* text)
|
|
81
|
+
- link(*string* href, *string* title, *string* text)
|
|
82
|
+
- image(*string* href, *string* title, *string* text)
|
|
83
|
+
- text(*string* text)
|
|
84
|
+
|
|
85
|
+
<h2 id="lexer">The lexer</h2>
|
|
86
|
+
|
|
87
|
+
The lexer is...
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
<h2 id="parser">The parser</h2>
|
|
91
|
+
|
|
92
|
+
The parser is...
|
|
93
|
+
|
|
94
|
+
***
|
|
95
|
+
|
|
96
|
+
<h2 id="extend">Access to lexer and parser</h2>
|
|
97
|
+
|
|
98
|
+
You also have direct access to the lexer and parser if you so desire.
|
|
99
|
+
|
|
100
|
+
``` js
|
|
101
|
+
var tokens = marked.lexer(text, options);
|
|
102
|
+
console.log(marked.parser(tokens));
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
``` js
|
|
106
|
+
var lexer = new marked.Lexer(options);
|
|
107
|
+
var tokens = lexer.lex(text);
|
|
108
|
+
console.log(tokens);
|
|
109
|
+
console.log(lexer.rules);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Pro level
|
|
113
|
+
|
|
114
|
+
You also have direct access to the lexer and parser if you so desire.
|
|
115
|
+
|
|
116
|
+
``` js
|
|
117
|
+
var tokens = marked.lexer(text, options);
|
|
118
|
+
console.log(marked.parser(tokens));
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
``` js
|
|
122
|
+
var lexer = new marked.Lexer(options);
|
|
123
|
+
var tokens = lexer.lex(text);
|
|
124
|
+
console.log(tokens);
|
|
125
|
+
console.log(lexer.rules);
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
``` bash
|
|
129
|
+
$ node
|
|
130
|
+
> require('marked').lexer('> i am using marked.')
|
|
131
|
+
[ { type: 'blockquote_start' },
|
|
132
|
+
{ type: 'paragraph',
|
|
133
|
+
text: 'i am using marked.' },
|
|
134
|
+
{ type: 'blockquote_end' },
|
|
135
|
+
links: {} ]
|
|
136
|
+
```
|