From 911780dcca8ebc91526d9a34b3220551662e8a9e Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Wed, 10 Jan 2018 01:22:20 +0100 Subject: [PATCH 1/5] fix def_blocks test: link reference definition cannot interrupt a paragraph + blockquote laziness rule, according to commonmark spec (see review of #974. Partial replay of 98ac7a4) --- test/new/def_blocks.html | 4 +++- test/new/def_blocks.md | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/new/def_blocks.html b/test/new/def_blocks.html index 14edc97a41..5d8de49c04 100644 --- a/test/new/def_blocks.html +++ b/test/new/def_blocks.html @@ -6,7 +6,8 @@
-

hello

+

hello +[2]: hello

@@ -24,5 +25,6 @@

foo bar +[5]: foo bar

diff --git a/test/new/def_blocks.md b/test/new/def_blocks.md index 4d16292987..f58fa4d37b 100644 --- a/test/new/def_blocks.md +++ b/test/new/def_blocks.md @@ -17,5 +17,5 @@ > foo > bar -[1]: foo +[5]: foo > bar From aece9b27329b728ea81ec96b4e7d1a227c6b0ab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D1=81=D1=82=D1=8F=20=D0=A2=D1=80=D0=B5=D1=82?= =?UTF-8?q?=D1=8F=D0=BA?= Date: Mon, 18 Dec 2017 23:44:19 +0200 Subject: [PATCH 2/5] Overwritten the test for a more precise wording. --- test/new/toplevel_paragraphs.html | 30 +++++++++++++++--------------- test/new/toplevel_paragraphs.md | 30 +++++++++++++++--------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/test/new/toplevel_paragraphs.html b/test/new/toplevel_paragraphs.html index 970c6f19f6..d15bfccef0 100644 --- a/test/new/toplevel_paragraphs.html +++ b/test/new/toplevel_paragraphs.html @@ -1,30 +1,30 @@

hello world - how are you - how are you

+ text after spaces + text after spaces

-

hello world

-
how are you
+

paragraph before code

+
text inside block code
-

hello world

+

paragraph before hr


-

hello world

+

paragraph before head with hash

how are you

-

hello world

+

paragraph before head with equals

how are you

-

hello world

-

how are you

+

paragraph before blockquote

+

text for blockquote

-

hello world

- +

paragraph before list

+ -

hello world

-
how are you
+

paragraph before div

+
text inside div
-

hello world -how are you

+

paragraph with span +text inside span

hello world

diff --git a/test/new/toplevel_paragraphs.md b/test/new/toplevel_paragraphs.md index 2c17c669bf..de29be7557 100644 --- a/test/new/toplevel_paragraphs.md +++ b/test/new/toplevel_paragraphs.md @@ -2,35 +2,35 @@ gfm: true --- hello world - how are you - how are you + text after spaces + text after spaces -hello world +paragraph before code ``` -how are you +text inside block code ``` -hello world +paragraph before hr * * * -hello world +paragraph before head with hash # how are you -hello world +paragraph before head with equals how are you =========== -hello world -> how are you +paragraph before blockquote +> text for blockquote -hello world -* how are you +paragraph before list +* text inside list -hello world -
how are you
+paragraph before div +
text inside div
-hello world -how are you +paragraph with span +text inside span hello [world][how] From 1a71ae06bf5bc10391c66fd47426039a4c6616d0 Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Wed, 10 Jan 2018 01:40:46 +0100 Subject: [PATCH 3/5] new blockquote rule: match any paragraph-like content up to next line (laziness rule), or anything on the current line. Change paragraph rule accordingly, and make it non-greedy --- lib/marked.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index 8279692a6f..caf62932a4 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -19,12 +19,12 @@ var block = { heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/, nptable: noop, lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/, - blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/, + blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/, list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/, html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/, def: /^ {0,3}\[(label)\]: *\n? *]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/, table: noop, - paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag))+)\n*/, + paragraph: /^([^\n]+(?:\n?(?!hr|heading|lheading| {0,3}>|tag)[^\n]+)+)/, text: /^[^\n]+/ }; @@ -47,10 +47,6 @@ block.list = replace(block.list) ('def', '\\n+(?=' + block.def.source + ')') (); -block.blockquote = replace(block.blockquote) - ('def', block.def) - (); - block._tag = '(?!(?:' + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code' + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo' @@ -67,10 +63,13 @@ block.paragraph = replace(block.paragraph) ('hr', block.hr) ('heading', block.heading) ('lheading', block.lheading) - ('blockquote', block.blockquote) ('tag', '<' + block._tag) (); +block.blockquote = replace(block.blockquote) + ('paragraph', block.paragraph) + (); + /** * Normal Block Grammar */ From f45dc385d9ba90fb8fd141f2fb0fee9db520d2d5 Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Wed, 10 Jan 2018 01:52:33 +0100 Subject: [PATCH 4/5] match setext headings just before paragraphs, then only paragraph continuations are matched inside blockquotes (see http://spec.commonmark.org/0.28/#example-197) --- lib/marked.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index caf62932a4..cbdd0ecdaa 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -18,12 +18,12 @@ var block = { hr: /^( *[-*_]){3,} *(?:\n+|$)/, heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/, nptable: noop, - lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/, blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/, list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/, html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/, def: /^ {0,3}\[(label)\]: *\n? *]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/, table: noop, + lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/, paragraph: /^([^\n]+(?:\n?(?!hr|heading|lheading| {0,3}>|tag)[^\n]+)+)/, text: /^[^\n]+/ }; @@ -244,17 +244,6 @@ Lexer.prototype.token = function(src, top) { continue; } - // lheading - if (cap = this.rules.lheading.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'heading', - depth: cap[2] === '=' ? 1 : 2, - text: cap[1] - }); - continue; - } - // hr if (cap = this.rules.hr.exec(src)) { src = src.substring(cap[0].length); @@ -422,6 +411,17 @@ Lexer.prototype.token = function(src, top) { continue; } + // lheading + if (cap = this.rules.lheading.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'heading', + depth: cap[2] === '=' ? 1 : 2, + text: cap[1] + }); + continue; + } + // top-level paragraph if (top && (cap = this.rules.paragraph.exec(src))) { src = src.substring(cap[0].length); From 399cf8235f2aee1c5ae432de859cc36aab8e30db Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Wed, 10 Jan 2018 02:21:43 +0100 Subject: [PATCH 5/5] add commonmark tests for blockquotes. Example 198 and 200 are disabled since they do not pass, FIXME --- test/new/cm_blockquotes.html | 239 +++++++++++++++++++++++++++++++++++ test/new/cm_blockquotes.md | 189 +++++++++++++++++++++++++++ 2 files changed, 428 insertions(+) create mode 100644 test/new/cm_blockquotes.html create mode 100644 test/new/cm_blockquotes.md diff --git a/test/new/cm_blockquotes.html b/test/new/cm_blockquotes.html new file mode 100644 index 0000000000..363f4e218a --- /dev/null +++ b/test/new/cm_blockquotes.html @@ -0,0 +1,239 @@ +

Example 191

+ +
+

Foo

+

bar +baz

+
+ +

Example 192

+ +

The spaces after the > characters can be omitted:

+ +
+

Foo

+

bar +baz

+
+ +

Example 193

+ +

The > characters can be indented 1-3 spaces:

+ +
+

Foo

+

bar +baz

+
+ +

Example 194

+ +

Four spaces gives us a code block:

+ +
> # Foo
+> bar
+> baz
+
+ +

Example 195

+ +

The Laziness clause allows us to omit the > before paragraph continuation text:

+ +
+

Foo

+

bar +baz

+
+ +

Example 196

+ +

A block quote can contain some lazy and some non-lazy continuation lines:

+ +
+

bar +baz +foo

+
+ +

Example 197

+ +

Laziness only applies to lines that would have been continuations of paragraphs had they been prepended with block quote markers. For example, the > cannot be omitted in the second line of

+ +
+

foo

+
+
+ +

without changing the meaning.

+ +

Example 198

+ +
Similarly, if we omit the `>` in the second line then the block quote ends after the first line:
+
+> - foo
+- bar
+ +

Example 199

+ +

For the same reason, we can’t omit the > in front of subsequent lines of an indented or fenced code block:

+ +
+
foo
+
+
+
bar
+
+ +

Example 200

+ +
> ```
+foo
+```
+
+<blockquote>
+<pre><code></code></pre>
+</blockquote>
+<p>foo</p>
+<pre><code></code></pre>
+
+ +

Example 201

+
> foo
+    - bar
+
+<blockquote>
+<p>foo
+- bar</p>
+</blockquote>
+
+ +

Example 202

+ +

A block quote can be empty:

+ +
+
+ +

Example 203

+ +
+
+ +

Example 204

+ +

A block quote can have initial or final blank lines:

+ +
+

foo

+
+ + +

Example 205

+ +

A blank line always separates block quotes:

+ +
+

foo

+
+
+

bar

+
+ +

Example 206

+ +

Consecutiveness means that if we put these block quotes together, we get a single block quote:

+ +
+

foo +bar

+
+ +

Example 207

+ +

To get a block quote with two paragraphs, use:

+ +
+

foo

+

bar

+
+ +

Example 208

+ +

Block quotes can interrupt paragraphs:

+ +

foo

+
+

bar

+
+ +

Example 209

+ +

In general, blank lines are not needed before or after block quotes:

+ +
+

aaa

+
+
+
+

bbb

+
+ +

Example 210

+ +

However, because of laziness, a blank line is needed between a block quote and a following paragraph:

+ +
+

bar +baz

+
+ +

Example 211

+ +
+

bar

+
+

baz

+ +

Example 212

+ +
+

bar

+
+

baz

+ +

Example 213

+ +

It is a consequence of the Laziness rule that any number of initial >s may be omitted on a continuation line of a nested block quote:

+ +
+
+
+

foo +bar

+
+
+
+ +

Example 214

+ +
+
+
+

foo +bar +baz

+
+
+
+ +

Example 215

+ +

When including an indented code block in a block quote, remember that the block quote marker includes both the > and a following space. So five spaces are needed after the >:

+ +
+
code
+
+
+
+

not code

+
diff --git a/test/new/cm_blockquotes.md b/test/new/cm_blockquotes.md new file mode 100644 index 0000000000..95a317de44 --- /dev/null +++ b/test/new/cm_blockquotes.md @@ -0,0 +1,189 @@ +### Example 191 + +> # Foo +> bar +> baz + +### Example 192 + +The spaces after the `>` characters can be omitted: + +># Foo +>bar +> baz + +### Example 193 + +The `>` characters can be indented 1-3 spaces: + + > # Foo + > bar + > baz + +### Example 194 + +Four spaces gives us a code block: + + > # Foo + > bar + > baz + +### Example 195 + +The Laziness clause allows us to omit the `>` before paragraph continuation text: + +> # Foo +> bar +baz + +### Example 196 + +A block quote can contain some lazy and some non-lazy continuation lines: + +> bar +baz +> foo + +### Example 197 + +Laziness only applies to lines that would have been continuations of paragraphs had they been prepended with block quote markers. For example, the `>` cannot be omitted in the second line of + +> foo +--- + +without changing the meaning. + +### Example 198 + + Similarly, if we omit the `>` in the second line then the block quote ends after the first line: + + > - foo + - bar + +### Example 199 + +For the same reason, we can’t omit the `>` in front of subsequent lines of an indented or fenced code block: + +> foo + + bar + +### Example 200 + + > ``` + foo + ``` + +
+
+
+

foo

+
+ +### Example 201 + + > foo + - bar + +
+

foo + - bar

+
+ +### Example 202 + +A block quote can be empty: + +> + +### Example 203 + +> +> +> + +### Example 204 + +A block quote can have initial or final blank lines: + +> +> foo +> + +### Example 205 + +A blank line always separates block quotes: + +> foo + +> bar + +### Example 206 + +Consecutiveness means that if we put these block quotes together, we get a single block quote: + +> foo +> bar + +### Example 207 + +To get a block quote with two paragraphs, use: + +> foo +> +> bar + +### Example 208 + +Block quotes can interrupt paragraphs: + +foo +> bar + +### Example 209 + +In general, blank lines are not needed before or after block quotes: + +> aaa +*** +> bbb + +### Example 210 + +However, because of laziness, a blank line is needed between a block quote and a following paragraph: + +> bar +baz + +### Example 211 + +> bar + +baz + +### Example 212 + +> bar +> +baz + +### Example 213 + +It is a consequence of the Laziness rule that any number of initial `>`s may be omitted on a continuation line of a nested block quote: + +> > > foo +bar + +### Example 214 + +>>> foo +> bar +>>baz + +### Example 215 + +When including an indented code block in a block quote, remember that the block quote marker includes both the `>` and a following space. So five spaces are needed after the `>`: + +> code + +> not code