marked 0.2.7 → 0.2.8
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/README.md +6 -0
- package/bin/marked +19 -6
- package/lib/marked.js +40 -15
- package/man/marked.1 +14 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,6 +72,10 @@ marked has a few different switches which change behavior.
|
|
|
72
72
|
- __tables__: Enable GFM tables. This is enabled by default. (Requires the
|
|
73
73
|
`gfm` option in order to be enabled).
|
|
74
74
|
- __breaks__: Enable GFM line breaks. Disabled by default.
|
|
75
|
+
- __smartLists__: Use smarter list behavior than the original markdown.
|
|
76
|
+
Disabled by default. May eventually be default with the old behavior
|
|
77
|
+
moved into `pedantic`.
|
|
78
|
+
- __langPrefix__: Set the prefix for code block classes. Defaults to `lang-`.
|
|
75
79
|
|
|
76
80
|
## Usage
|
|
77
81
|
|
|
@@ -83,6 +87,8 @@ marked.setOptions({
|
|
|
83
87
|
breaks: false,
|
|
84
88
|
pedantic: false,
|
|
85
89
|
sanitize: true,
|
|
90
|
+
smartLists: true,
|
|
91
|
+
langPrefix: 'language-',
|
|
86
92
|
highlight: function(code, lang) {
|
|
87
93
|
if (lang === 'js') {
|
|
88
94
|
return highlighter.javascript(code);
|
package/bin/marked
CHANGED
|
@@ -38,7 +38,8 @@ function main(argv, callback) {
|
|
|
38
38
|
, input
|
|
39
39
|
, output
|
|
40
40
|
, arg
|
|
41
|
-
, tokens
|
|
41
|
+
, tokens
|
|
42
|
+
, opt;
|
|
42
43
|
|
|
43
44
|
function getarg() {
|
|
44
45
|
var arg = argv.shift();
|
|
@@ -88,12 +89,18 @@ function main(argv, callback) {
|
|
|
88
89
|
return help();
|
|
89
90
|
default:
|
|
90
91
|
if (arg.indexOf('--') === 0) {
|
|
91
|
-
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
opt = camelize(arg.replace(/^--(no-)?/, ''));
|
|
93
|
+
if (!marked.defaults.hasOwnProperty(opt)) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (arg.indexOf('--no-') === 0) {
|
|
97
|
+
options[opt] = typeof marked.defaults[opt] !== 'boolean'
|
|
98
|
+
? null
|
|
99
|
+
: false;
|
|
95
100
|
} else {
|
|
96
|
-
options[
|
|
101
|
+
options[opt] = typeof marked.defaults[opt] !== 'boolean'
|
|
102
|
+
? argv.shift()
|
|
103
|
+
: true;
|
|
97
104
|
}
|
|
98
105
|
} else {
|
|
99
106
|
files.push(arg);
|
|
@@ -157,6 +164,12 @@ function getStdin(callback) {
|
|
|
157
164
|
}
|
|
158
165
|
}
|
|
159
166
|
|
|
167
|
+
function camelize(text) {
|
|
168
|
+
return text.replace(/(\w)-(\w)/g, function(_, a, b) {
|
|
169
|
+
return a + b.toUpperCase();
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
160
173
|
/**
|
|
161
174
|
* Expose / Entry Point
|
|
162
175
|
*/
|
package/lib/marked.js
CHANGED
|
@@ -21,9 +21,9 @@ var block = {
|
|
|
21
21
|
blockquote: /^( *>[^\n]+(\n[^\n]+)*\n*)+/,
|
|
22
22
|
list: /^( *)(bull) [\s\S]+?(?:hr|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
|
|
23
23
|
html: /^ *(?:comment|closed|closing) *(?:\n{2,}|\s*$)/,
|
|
24
|
-
def: /^ *\[([^\]]+)\]:
|
|
24
|
+
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
|
|
25
25
|
table: noop,
|
|
26
|
-
paragraph: /^([^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))
|
|
26
|
+
paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
|
|
27
27
|
text: /^[^\n]+/
|
|
28
28
|
};
|
|
29
29
|
|
|
@@ -144,6 +144,8 @@ Lexer.prototype.token = function(src, top) {
|
|
|
144
144
|
, next
|
|
145
145
|
, loose
|
|
146
146
|
, cap
|
|
147
|
+
, bull
|
|
148
|
+
, b
|
|
147
149
|
, item
|
|
148
150
|
, space
|
|
149
151
|
, i
|
|
@@ -281,6 +283,11 @@ Lexer.prototype.token = function(src, top) {
|
|
|
281
283
|
// Get each top-level item.
|
|
282
284
|
cap = cap[0].match(this.rules.item);
|
|
283
285
|
|
|
286
|
+
// Get bullet.
|
|
287
|
+
if (this.options.smartLists) {
|
|
288
|
+
bull = block.bullet.exec(cap[0])[0];
|
|
289
|
+
}
|
|
290
|
+
|
|
284
291
|
next = false;
|
|
285
292
|
l = cap.length;
|
|
286
293
|
i = 0;
|
|
@@ -302,6 +309,16 @@ Lexer.prototype.token = function(src, top) {
|
|
|
302
309
|
: item.replace(/^ {1,4}/gm, '');
|
|
303
310
|
}
|
|
304
311
|
|
|
312
|
+
// Determine whether the next list item belongs here.
|
|
313
|
+
// Backpedal if it does not belong in this list.
|
|
314
|
+
if (this.options.smartLists && i !== l - 1) {
|
|
315
|
+
b = block.bullet.exec(cap[i+1])[0];
|
|
316
|
+
if (bull !== b && !(bull[1] === '.' && b[1] === '.')) {
|
|
317
|
+
src = cap.slice(i + 1).join('\n') + src;
|
|
318
|
+
i = l - 1;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
305
322
|
// Determine whether item is loose or not.
|
|
306
323
|
// Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
|
|
307
324
|
// for discount behavior.
|
|
@@ -394,7 +411,9 @@ Lexer.prototype.token = function(src, top) {
|
|
|
394
411
|
src = src.substring(cap[0].length);
|
|
395
412
|
this.tokens.push({
|
|
396
413
|
type: 'paragraph',
|
|
397
|
-
text: cap[
|
|
414
|
+
text: cap[1][cap[1].length-1] === '\n'
|
|
415
|
+
? cap[1].slice(0, -1)
|
|
416
|
+
: cap[1]
|
|
398
417
|
});
|
|
399
418
|
continue;
|
|
400
419
|
}
|
|
@@ -424,7 +443,7 @@ Lexer.prototype.token = function(src, top) {
|
|
|
424
443
|
*/
|
|
425
444
|
|
|
426
445
|
var inline = {
|
|
427
|
-
escape: /^\\([\\`*{}\[\]()#+\-.!_
|
|
446
|
+
escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
|
|
428
447
|
autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
|
|
429
448
|
url: noop,
|
|
430
449
|
tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
|
|
@@ -433,7 +452,7 @@ var inline = {
|
|
|
433
452
|
nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
|
|
434
453
|
strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
|
|
435
454
|
em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
|
|
436
|
-
code: /^(`+)([\s\S]*?[^`])\1(?!`)/,
|
|
455
|
+
code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
|
|
437
456
|
br: /^ {2,}\n(?!\s*$)/,
|
|
438
457
|
del: noop,
|
|
439
458
|
text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
|
|
@@ -471,9 +490,9 @@ inline.pedantic = merge({}, inline.normal, {
|
|
|
471
490
|
*/
|
|
472
491
|
|
|
473
492
|
inline.gfm = merge({}, inline.normal, {
|
|
474
|
-
escape: replace(inline.escape)('])', '
|
|
475
|
-
url: /^(https?:\/\/[^\s]+[
|
|
476
|
-
del:
|
|
493
|
+
escape: replace(inline.escape)('])', '~|])')(),
|
|
494
|
+
url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
|
|
495
|
+
del: /^~~(?=\S)([\s\S]*?\S)~~/,
|
|
477
496
|
text: replace(inline.text)
|
|
478
497
|
(']|', '~]|')
|
|
479
498
|
('|', '|https?://|')
|
|
@@ -524,8 +543,8 @@ InlineLexer.rules = inline;
|
|
|
524
543
|
* Static Lexing/Compiling Method
|
|
525
544
|
*/
|
|
526
545
|
|
|
527
|
-
InlineLexer.output = function(src, links,
|
|
528
|
-
var inline = new InlineLexer(links,
|
|
546
|
+
InlineLexer.output = function(src, links, options) {
|
|
547
|
+
var inline = new InlineLexer(links, options);
|
|
529
548
|
return inline.output(src);
|
|
530
549
|
};
|
|
531
550
|
|
|
@@ -828,7 +847,8 @@ Parser.prototype.tok = function() {
|
|
|
828
847
|
|
|
829
848
|
return '<pre><code'
|
|
830
849
|
+ (this.token.lang
|
|
831
|
-
? ' class="
|
|
850
|
+
? ' class="'
|
|
851
|
+
+ this.options.langPrefix
|
|
832
852
|
+ this.token.lang
|
|
833
853
|
+ '"'
|
|
834
854
|
: '')
|
|
@@ -993,11 +1013,14 @@ function merge(obj) {
|
|
|
993
1013
|
|
|
994
1014
|
function marked(src, opt) {
|
|
995
1015
|
try {
|
|
1016
|
+
if (opt) opt = merge({}, marked.defaults, opt);
|
|
996
1017
|
return Parser.parse(Lexer.lex(src, opt), opt);
|
|
997
1018
|
} catch (e) {
|
|
998
1019
|
e.message += '\nPlease report this to https://github.com/chjj/marked.';
|
|
999
1020
|
if ((opt || marked.defaults).silent) {
|
|
1000
|
-
return 'An error occured
|
|
1021
|
+
return '<p>An error occured:</p><pre>'
|
|
1022
|
+
+ escape(e.message + '', true)
|
|
1023
|
+
+ '</pre>';
|
|
1001
1024
|
}
|
|
1002
1025
|
throw e;
|
|
1003
1026
|
}
|
|
@@ -1009,7 +1032,7 @@ function marked(src, opt) {
|
|
|
1009
1032
|
|
|
1010
1033
|
marked.options =
|
|
1011
1034
|
marked.setOptions = function(opt) {
|
|
1012
|
-
marked.defaults
|
|
1035
|
+
merge(marked.defaults, opt);
|
|
1013
1036
|
return marked;
|
|
1014
1037
|
};
|
|
1015
1038
|
|
|
@@ -1019,8 +1042,10 @@ marked.defaults = {
|
|
|
1019
1042
|
breaks: false,
|
|
1020
1043
|
pedantic: false,
|
|
1021
1044
|
sanitize: false,
|
|
1045
|
+
smartLists: false,
|
|
1022
1046
|
silent: false,
|
|
1023
|
-
highlight: null
|
|
1047
|
+
highlight: null,
|
|
1048
|
+
langPrefix: 'lang-'
|
|
1024
1049
|
};
|
|
1025
1050
|
|
|
1026
1051
|
/**
|
|
@@ -1038,7 +1063,7 @@ marked.inlineLexer = InlineLexer.output;
|
|
|
1038
1063
|
|
|
1039
1064
|
marked.parse = marked;
|
|
1040
1065
|
|
|
1041
|
-
if (typeof
|
|
1066
|
+
if (typeof exports === 'object') {
|
|
1042
1067
|
module.exports = marked;
|
|
1043
1068
|
} else if (typeof define === 'function' && define.amd) {
|
|
1044
1069
|
define(function() { return marked; });
|
package/man/marked.1
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
.ds q \N'34'
|
|
2
|
-
.TH marked 1
|
|
2
|
+
.TH marked 1 "2013-01-05" "v0.2.7" "marked.js"
|
|
3
3
|
|
|
4
4
|
.SH NAME
|
|
5
5
|
marked \- a javascript markdown parser
|
|
6
6
|
|
|
7
7
|
.SH SYNOPSIS
|
|
8
8
|
.B marked
|
|
9
|
-
[\-o output] [\-i input] [\-\-help]
|
|
9
|
+
[\-o \fI<output>\fP] [\-i \fI<input>\fP] [\-\-help]
|
|
10
10
|
[\-\-tokens] [\-\-pedantic] [\-\-gfm]
|
|
11
11
|
[\-\-breaks] [\-\-tables] [\-\-sanitize]
|
|
12
|
-
[\-\-
|
|
12
|
+
[\-\-smart\-lists] [\-\-lang\-prefix \fI<prefix>\fP]
|
|
13
|
+
[\-\-no\-etc...] [\-\-silent] [\fIfilename\fP]
|
|
13
14
|
|
|
14
15
|
.SH DESCRIPTION
|
|
15
16
|
.B marked
|
|
@@ -28,10 +29,10 @@ marked --output="hello world.html" -i in.md --no-breaks
|
|
|
28
29
|
|
|
29
30
|
.SH OPTIONS
|
|
30
31
|
.TP
|
|
31
|
-
.BI \-o,\ \-\-output\ [
|
|
32
|
+
.BI \-o,\ \-\-output\ [\fIoutput\fP]
|
|
32
33
|
Specify file output. If none is specified, write to stdout.
|
|
33
34
|
.TP
|
|
34
|
-
.BI \-i,\ \-\-input\ [
|
|
35
|
+
.BI \-i,\ \-\-input\ [\fIinput\fP]
|
|
35
36
|
Specify file input, otherwise use last argument as input file. If no input file
|
|
36
37
|
is specified, read from stdin.
|
|
37
38
|
.TP
|
|
@@ -54,6 +55,12 @@ Enable GFM tables. Only works with the gfm option.
|
|
|
54
55
|
.BI \-\-sanitize
|
|
55
56
|
Sanitize output. Ignore any HTML input.
|
|
56
57
|
.TP
|
|
58
|
+
.BI \-\-smart\-lists
|
|
59
|
+
Use smarter list behavior than the original markdown.
|
|
60
|
+
.TP
|
|
61
|
+
.BI \-\-lang\-prefix\ [\fIprefix\fP]
|
|
62
|
+
Set the prefix for code block classes.
|
|
63
|
+
.TP
|
|
57
64
|
.BI \-\-no\-sanitize,\ \-no-etc...
|
|
58
65
|
The inverse of any of the marked options above.
|
|
59
66
|
.TP
|
|
@@ -74,8 +81,8 @@ For configuring and running programmatically.
|
|
|
74
81
|
Please report any bugs to https://github.com/chjj/marked.
|
|
75
82
|
|
|
76
83
|
.SH LICENSE
|
|
77
|
-
Copyright (c) 2011-2013, Christopher Jeffrey (MIT License)
|
|
84
|
+
Copyright (c) 2011-2013, Christopher Jeffrey (MIT License).
|
|
78
85
|
|
|
79
|
-
.SH SEE ALSO
|
|
86
|
+
.SH "SEE ALSO"
|
|
80
87
|
.BR markdown(1),
|
|
81
88
|
.BR node.js(1)
|