Skip to content

Commit ac1e57c

Browse files
authored
use correct options in specs (#1511)
use correct options in specs
2 parents 63935f9 + 0276ad7 commit ac1e57c

16 files changed

+5474
-176
lines changed

docs/USING_ADVANCED.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ marked.setOptions({
2525
},
2626
pedantic: false,
2727
gfm: true,
28-
tables: true,
2928
breaks: false,
3029
sanitize: false,
3130
smartLists: true,
@@ -56,7 +55,6 @@ console.log(marked(markdownString));
5655
|silent |`boolean` |`false` |v0.2.7 |If true, the parser does not throw any exception.|
5756
|smartLists |`boolean` |`false` |v0.2.8 |If true, use smarter list behavior than those found in `markdown.pl`.|
5857
|smartypants |`boolean` |`false` |v0.2.9 |If true, use "smart" typographic punctuation for things like quotes and dashes.|
59-
|tables |`boolean` |`true` |v0.2.7 |If true and `gfm` is true, use [GFM Tables extension](https://github.github.com/gfm/#tables-extension-).|
6058
|xhtml |`boolean` |`false` |v0.3.2 |If true, emit self-closing HTML tags for void elements (<br/>, <img/>, etc.) with a "/" as required by XHTML.|
6159

6260
<h2 id="highlight">Asynchronous highlighting</h2>

lib/marked.js

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
var block = {
1515
newline: /^\n+/,
1616
code: /^( {4}[^\n]+\n*)+/,
17-
fences: noop,
17+
fences: /^ {0,3}(`{3,}|~{3,})([^`~\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
1818
hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
19-
heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,
20-
nptable: noop,
19+
heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/,
2120
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
2221
list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
2322
html: '^ {0,3}(?:' // optional indentation
@@ -31,9 +30,12 @@ var block = {
3130
+ '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag
3231
+ ')',
3332
def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
33+
nptable: noop,
3434
table: noop,
35-
lheading: /^([^\n]+)\n {0,3}(=|-){2,} *(?:\n+|$)/,
36-
paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading| {0,3}>|<\/?(?:tag)(?: +|\n|\/?>)|<(?:script|pre|style|!--))[^\n]+)*)/,
35+
lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
36+
// regex template, placeholders will be replaced according to different paragraph
37+
// interruption rules of commonmark and the original markdown spec:
38+
_paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/,
3739
text: /^[^\n]+/
3840
};
3941

@@ -69,10 +71,14 @@ block.html = edit(block.html, 'i')
6971
.replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/)
7072
.getRegex();
7173

72-
block.paragraph = edit(block.paragraph)
74+
block.paragraph = edit(block._paragraph)
7375
.replace('hr', block.hr)
74-
.replace('heading', block.heading)
75-
.replace('lheading', block.lheading)
76+
.replace('heading', ' {0,3}#{1,6} +')
77+
.replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
78+
.replace('blockquote', ' {0,3}>')
79+
.replace('fences', ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n')
80+
.replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
81+
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
7682
.replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
7783
.getRegex();
7884

@@ -91,28 +97,12 @@ block.normal = merge({}, block);
9197
*/
9298

9399
block.gfm = merge({}, block.normal, {
94-
fences: /^ {0,3}(`{3,}|~{3,})([^`\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
95-
paragraph: /^/,
96-
heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
97-
});
98-
99-
block.gfm.paragraph = edit(block.paragraph)
100-
.replace('(?!', '(?!'
101-
+ block.gfm.fences.source.replace('\\1', '\\2') + '|'
102-
+ block.list.source.replace('\\1', '\\3') + '|')
103-
.getRegex();
104-
105-
/**
106-
* GFM + Tables Block Grammar
107-
*/
108-
109-
block.tables = merge({}, block.gfm, {
110100
nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/,
111101
table: /^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/
112102
});
113103

114104
/**
115-
* Pedantic grammar
105+
* Pedantic grammar (original John Gruber's loose markdown specification)
116106
*/
117107

118108
block.pedantic = merge({}, block.normal, {
@@ -126,7 +116,18 @@ block.pedantic = merge({}, block.normal, {
126116
+ '|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)'
127117
+ '\\b)\\w+(?!:|[^\\w\\s@]*@)\\b')
128118
.getRegex(),
129-
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/
119+
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
120+
heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,
121+
fences: noop, // fences not supported
122+
paragraph: edit(block.normal._paragraph)
123+
.replace('hr', block.hr)
124+
.replace('heading', ' *#{1,6} *[^\n]')
125+
.replace('lheading', block.lheading)
126+
.replace('blockquote', ' {0,3}>')
127+
.replace('|fences', '')
128+
.replace('|list', '')
129+
.replace('|html', '')
130+
.getRegex()
130131
});
131132

132133
/**
@@ -142,11 +143,7 @@ function Lexer(options) {
142143
if (this.options.pedantic) {
143144
this.rules = block.pedantic;
144145
} else if (this.options.gfm) {
145-
if (this.options.tables) {
146-
this.rules = block.tables;
147-
} else {
148-
this.rules = block.gfm;
149-
}
146+
this.rules = block.gfm;
150147
}
151148
}
152149

@@ -233,7 +230,7 @@ Lexer.prototype.token = function(src, top) {
233230
continue;
234231
}
235232

236-
// fences (gfm)
233+
// fences
237234
if (cap = this.rules.fences.exec(src)) {
238235
src = src.substring(cap[0].length);
239236
this.tokens.push({
@@ -494,7 +491,7 @@ Lexer.prototype.token = function(src, top) {
494491
src = src.substring(cap[0].length);
495492
this.tokens.push({
496493
type: 'heading',
497-
depth: cap[2] === '=' ? 1 : 2,
494+
depth: cap[2].charAt(0) === '=' ? 1 : 2,
498495
text: cap[1]
499496
});
500497
continue;
@@ -1671,7 +1668,6 @@ marked.getDefaults = function() {
16711668
silent: false,
16721669
smartLists: false,
16731670
smartypants: false,
1674-
tables: true,
16751671
xhtml: false
16761672
};
16771673
};

man/marked.1

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ marked \- a javascript markdown parser
88
.B marked
99
[\-o \fI<output>\fP] [\-i \fI<input>\fP] [\-\-help]
1010
[\-\-tokens] [\-\-pedantic] [\-\-gfm]
11-
[\-\-breaks] [\-\-tables] [\-\-sanitize]
11+
[\-\-breaks] [\-\-sanitize]
1212
[\-\-smart\-lists] [\-\-lang\-prefix \fI<prefix>\fP]
1313
[\-\-no\-etc...] [\-\-silent] [\fIfilename\fP]
1414

@@ -72,9 +72,6 @@ Enable github flavored markdown.
7272
.BI \-\-breaks
7373
Enable GFM line breaks. Only works with the gfm option.
7474
.TP
75-
.BI \-\-tables
76-
Enable GFM tables. Only works with the gfm option.
77-
.TP
7875
.BI \-\-sanitize
7976
Sanitize output. Ignore any HTML input.
8077
.TP

man/marked.1.txt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ NAME
44
marked - a javascript markdown parser
55

66
SYNOPSIS
7-
marked [-o <output>] [-i <input>] [--help] [--tokens]
8-
[--pedantic] [--gfm] [--breaks] [--tables] [--sanitize]
9-
[--smart-lists] [--lang-prefix <prefix>] [--no-etc...] [--silent]
10-
[filename]
7+
marked [-o <output>] [-i <input>] [--help] [--tokens] [--pedantic]
8+
[--gfm] [--breaks] [--sanitize] [--smart-lists] [--lang-prefix <pre-
9+
fix>] [--no-etc...] [--silent] [filename]
10+
1111

1212
DESCRIPTION
1313
marked is a full-featured javascript markdown parser, built for speed.
@@ -56,9 +56,6 @@ OPTIONS
5656
--breaks
5757
Enable GFM line breaks. Only works with the gfm option.
5858

59-
--tables
60-
Enable GFM tables. Only works with the gfm option.
61-
6259
--sanitize
6360
Sanitize output. Ignore any HTML input.
6461

test/bench.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ function runBench(options) {
2929
// Non-GFM, Non-pedantic
3030
marked.setOptions({
3131
gfm: false,
32-
tables: false,
3332
breaks: false,
3433
pedantic: false,
3534
sanitize: false,
@@ -43,7 +42,6 @@ function runBench(options) {
4342
// GFM
4443
marked.setOptions({
4544
gfm: true,
46-
tables: false,
4745
breaks: false,
4846
pedantic: false,
4947
sanitize: false,
@@ -57,7 +55,6 @@ function runBench(options) {
5755
// Pedantic
5856
marked.setOptions({
5957
gfm: false,
60-
tables: false,
6158
breaks: false,
6259
pedantic: true,
6360
sanitize: false,

test/helpers/load.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,17 @@ function loadFiles(dir) {
7979
switch (ext) {
8080
case '.md': {
8181
const content = fm(fs.readFileSync(absFile, 'utf8'));
82+
const skip = content.attributes.skip;
83+
delete content.attributes.skip;
84+
const only = content.attributes.only;
85+
delete content.attributes.only;
8286
specs = [{
8387
section: name,
8488
markdown: content.body,
8589
html: fs.readFileSync(absFile.replace(/[^.]+$/, 'html'), 'utf8'),
86-
options: content.attributes
90+
options: content.attributes,
91+
only,
92+
skip
8793
}];
8894
break;
8995
}

test/specs/commonmark/commonmark.0.29.json

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -358,17 +358,15 @@
358358
"example": 45,
359359
"start_line": 915,
360360
"end_line": 919,
361-
"section": "ATX headings",
362-
"shouldFail": true
361+
"section": "ATX headings"
363362
},
364363
{
365364
"markdown": "### foo \\###\n## foo #\\##\n# foo \\#\n",
366365
"html": "<h3>foo ###</h3>\n<h2>foo ###</h2>\n<h1>foo #</h1>\n",
367366
"example": 46,
368367
"start_line": 925,
369368
"end_line": 933,
370-
"section": "ATX headings",
371-
"shouldFail": true
369+
"section": "ATX headings"
372370
},
373371
{
374372
"markdown": "****\n## foo\n****\n",
@@ -427,8 +425,7 @@
427425
"example": 53,
428426
"start_line": 1046,
429427
"end_line": 1055,
430-
"section": "Setext headings",
431-
"shouldFail": true
428+
"section": "Setext headings"
432429
},
433430
{
434431
"markdown": " Foo\n---\n\n Foo\n-----\n\n Foo\n ===\n",
@@ -508,8 +505,7 @@
508505
"example": 63,
509506
"start_line": 1186,
510507
"end_line": 1196,
511-
"section": "Setext headings",
512-
"shouldFail": true
508+
"section": "Setext headings"
513509
},
514510
{
515511
"markdown": "- Foo\n---\n",
@@ -1650,8 +1646,7 @@
16501646
"example": 205,
16511647
"start_line": 3464,
16521648
"end_line": 3476,
1653-
"section": "Block quotes",
1654-
"shouldFail": true
1649+
"section": "Block quotes"
16551650
},
16561651
{
16571652
"markdown": "> foo\n bar\n",
@@ -2220,8 +2215,7 @@
22202215
"example": 274,
22212216
"start_line": 5005,
22222217
"end_line": 5011,
2223-
"section": "Lists",
2224-
"shouldFail": true
2218+
"section": "Lists"
22252219
},
22262220
{
22272221
"markdown": "The number of windows in my house is\n1. The number of doors is 6.\n",
@@ -2366,8 +2360,7 @@
23662360
"example": 291,
23672361
"start_line": 5379,
23682362
"end_line": 5397,
2369-
"section": "Lists",
2370-
"shouldFail": true
2363+
"section": "Lists"
23712364
},
23722365
{
23732366
"markdown": "- a\n",
@@ -4904,8 +4897,7 @@
49044897
"example": 598,
49054898
"start_line": 8787,
49064899
"end_line": 8791,
4907-
"section": "Autolinks",
4908-
"shouldFail": true
4900+
"section": "Autolinks"
49094901
},
49104902
{
49114903
"markdown": "<http://example.com/\\[\\>\n",
@@ -4953,8 +4945,7 @@
49534945
"example": 604,
49544946
"start_line": 8850,
49554947
"end_line": 8854,
4956-
"section": "Autolinks",
4957-
"shouldFail": true
4948+
"section": "Autolinks"
49584949
},
49594950
{
49604951
"markdown": "<m:abc>\n",
@@ -4978,17 +4969,15 @@
49784969
"example": 607,
49794970
"start_line": 8871,
49804971
"end_line": 8875,
4981-
"section": "Autolinks",
4982-
"shouldFail": true
4972+
"section": "Autolinks"
49834973
},
49844974
{
49854975
"markdown": "[email protected]\n",
49864976
"html": "<p>[email protected]</p>\n",
49874977
"example": 608,
49884978
"start_line": 8878,
49894979
"end_line": 8882,
4990-
"section": "Autolinks",
4991-
"shouldFail": true
4980+
"section": "Autolinks"
49924981
},
49934982
{
49944983
"markdown": "<a><bab><c2c>\n",

0 commit comments

Comments
 (0)