diff --git a/lib/marked.js b/lib/marked.js index 8279692a6f..cbdd0ecdaa 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -18,13 +18,13 @@ var block = { hr: /^( *[-*_]){3,} *(?:\n+|$)/, 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? *([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/, table: noop, - paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag))+)\n*/, + lheading: /^([^\n]+)\n *(=|-){2,} *(?:\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 */ @@ -245,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); @@ -423,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); 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 @@ +
++ +Foo
+bar +baz
+
The spaces after the >
characters can be omitted:
++ +Foo
+bar +baz
+
The >
characters can be indented 1-3 spaces:
++ +Foo
+bar +baz
+
Four spaces gives us a code block:
+ +> # Foo
+> bar
+> baz
+
+
+The Laziness clause allows us to omit the >
before paragraph continuation text:
++ +Foo
+bar +baz
+
A block quote can contain some lazy and some non-lazy continuation lines:
+ +++ +bar +baz +foo
+
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.
+ +Similarly, if we omit the `>` in the second line then the block quote ends after the first line:
+
+> - foo
+- bar
+
+For the same reason, we can’t omit the >
in front of subsequent lines of an indented or fenced code block:
+++foo +
bar
+
+
+> ```
+foo
+```
+
+<blockquote>
+<pre><code></code></pre>
+</blockquote>
+<p>foo</p>
+<pre><code></code></pre>
+
+
+> foo
+ - bar
+
+<blockquote>
+<p>foo
+- bar</p>
+</blockquote>
+
+
+A block quote can be empty:
+ +++ +
++ +
A block quote can have initial or final blank lines:
+ +++ + +foo
+
A blank line always separates block quotes:
+ +++foo
+
++ +bar
+
Consecutiveness means that if we put these block quotes together, we get a single block quote:
+ +++ +foo +bar
+
To get a block quote with two paragraphs, use:
+ +++ +foo
+bar
+
Block quotes can interrupt paragraphs:
+ +foo
+++ +bar
+
In general, blank lines are not needed before or after block quotes:
+ +++aaa
+
++ +bbb
+
However, because of laziness, a blank line is needed between a block quote and a following paragraph:
+ +++ +bar +baz
+
++bar
+
baz
+ +++bar
+
baz
+ +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
+
++ +++++foo +bar +baz
+
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 +
+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 + ``` + +not code
+
+++
foo
+
+
+### Example 201
+
+ > 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 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 @@foo + - bar
+
-@@ -24,5 +25,6 @@hello
+hello +[2]: hello
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 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 @@foo bar +[5]: foo bar
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
hello world
+paragraph before head with equals
hello world
-+how are you
paragraph before blockquote
+-text for blockquote
hello world
-paragraph before list
+hello world
-paragraph before 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 -