New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use correct options in specs #1511
Changes from 10 commits
4b6a6e7
ef4904d
900114a
57f6d89
ba2eedd
8ccc1f1
f478dfb
7bc6e3f
7ed2692
d2e85d9
44dbeeb
1f4c17f
0276ad7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,9 @@ | |
var block = { | ||
newline: /^\n+/, | ||
code: /^( {4}[^\n]+\n*)+/, | ||
fences: noop, | ||
fences: /^ {0,3}(`{3,}|~{3,})([^`~\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/, | ||
hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/, | ||
heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/, | ||
nptable: noop, | ||
heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/, | ||
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/, | ||
list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/, | ||
html: '^ {0,3}(?:' // optional indentation | ||
|
@@ -31,9 +30,12 @@ var block = { | |
+ '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag | ||
+ ')', | ||
def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/, | ||
nptable: noop, | ||
table: noop, | ||
lheading: /^([^\n]+)\n {0,3}(=|-){2,} *(?:\n+|$)/, | ||
paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading| {0,3}>|<\/?(?:tag)(?: +|\n|\/?>)|<(?:script|pre|style|!--))[^\n]+)*)/, | ||
lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
// regex template, placeholders will be replaced according to different paragraph | ||
// interruption rules of commonmark and the original markdown spec: | ||
_paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
text: /^[^\n]+/ | ||
}; | ||
|
||
|
@@ -69,10 +71,14 @@ block.html = edit(block.html, 'i') | |
.replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/) | ||
.getRegex(); | ||
|
||
block.paragraph = edit(block.paragraph) | ||
block.paragraph = edit(block._paragraph) | ||
.replace('hr', block.hr) | ||
.replace('heading', block.heading) | ||
.replace('lheading', block.lheading) | ||
.replace('heading', ' {0,3}#{1,6} +') | ||
.replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs | ||
.replace('blockquote', ' {0,3}>') | ||
.replace('fences', ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n') | ||
.replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt | ||
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)') | ||
.replace('tag', block._tag) // pars can be interrupted by type (6) html blocks | ||
.getRegex(); | ||
|
||
|
@@ -91,28 +97,18 @@ block.normal = merge({}, block); | |
*/ | ||
|
||
block.gfm = merge({}, block.normal, { | ||
fences: /^ {0,3}(`{3,}|~{3,})([^`\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/, | ||
paragraph: /^/, | ||
heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/ | ||
nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Super-linear.
|
||
table: /^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same genre of problem as the
(Note, here and elsewhere I'm just checking regexes, not full exploitability). |
||
}); | ||
|
||
block.gfm.paragraph = edit(block.paragraph) | ||
.replace('(?!', '(?!' | ||
+ block.gfm.fences.source.replace('\\1', '\\2') + '|' | ||
+ block.list.source.replace('\\1', '\\3') + '|') | ||
.getRegex(); | ||
|
||
/** | ||
* GFM + Tables Block Grammar | ||
*/ | ||
|
||
block.tables = merge({}, block.gfm, { | ||
nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/, | ||
table: /^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/ | ||
}); | ||
block.tables = merge({}, block.gfm); | ||
|
||
/** | ||
* Pedantic grammar | ||
* Pedantic grammar (original John Gruber's loose markdown specification) | ||
*/ | ||
|
||
block.pedantic = merge({}, block.normal, { | ||
|
@@ -126,7 +122,18 @@ block.pedantic = merge({}, block.normal, { | |
+ '|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)' | ||
+ '\\b)\\w+(?!:|[^\\w\\s@]*@)\\b') | ||
.getRegex(), | ||
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/ | ||
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/, | ||
heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/, | ||
fences: noop, // fences not supported | ||
paragraph: edit(block.normal._paragraph) | ||
.replace('hr', block.hr) | ||
.replace('heading', ' *#{1,6} *[^\n]') | ||
.replace('lheading', block.lheading) | ||
.replace('blockquote', ' {0,3}>') | ||
.replace('|fences', '') | ||
.replace('|list', '') | ||
.replace('|html', '') | ||
.getRegex() | ||
}); | ||
|
||
/** | ||
|
@@ -233,7 +240,7 @@ Lexer.prototype.token = function(src, top) { | |
continue; | ||
} | ||
|
||
// fences (gfm) | ||
// fences | ||
if (cap = this.rules.fences.exec(src)) { | ||
src = src.substring(cap[0].length); | ||
this.tokens.push({ | ||
|
@@ -494,7 +501,7 @@ Lexer.prototype.token = function(src, top) { | |
src = src.substring(cap[0].length); | ||
this.tokens.push({ | ||
type: 'heading', | ||
depth: cap[2] === '=' ? 1 : 2, | ||
depth: cap[2].charAt(0) === '=' ? 1 : 2, | ||
text: cap[1] | ||
}); | ||
continue; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK