Skip to content

Commit

Permalink
fix(blockGamut): fix for headings inside blockquotes
Browse files Browse the repository at this point in the history
The spec states that you can be lazy and only put the `>` before the first line of a hard-wrapped paragraph.
It also states that blocquotes can contain any other md element inside.
This means headings and horizontal rules should be included in the blockquote but, right now, are treated as
independent entities

Closes #191
  • Loading branch information
tivie committed Aug 23, 2015
1 parent 7dc3fb1 commit 3df7062
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 9 deletions.
8 changes: 5 additions & 3 deletions dist/showdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/subParsers/blockGamut.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
showdown.subParser('blockGamut', function (text, options, globals) {
'use strict';

// we parse blockquotes first so that we can have headings and hrs
// inside blockquotes
text = showdown.subParser('blockQuotes')(text, options, globals);
text = showdown.subParser('headers')(text, options, globals);

// Do Horizontal Rules:
Expand All @@ -16,7 +19,6 @@ showdown.subParser('blockGamut', function (text, options, globals) {
text = showdown.subParser('tables')(text, options, globals);
text = showdown.subParser('lists')(text, options, globals);
text = showdown.subParser('codeBlocks')(text, options, globals);
text = showdown.subParser('blockQuotes')(text, options, globals);

// We already ran _HashHTMLBlocks() before, in Markdown(), but that
// was to escape raw HTML in the original Markdown source. This time,
Expand Down
2 changes: 1 addition & 1 deletion src/subParsers/blockQuotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ showdown.subParser('blockQuotes', function (text, options, globals) {
/gm, function(){...});
*/

text = text.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm, function (wholeMatch, m1) {
text = text.replace(/((^[ \t]{0,3}>[ \t]?.+\n(.+\n)*\n*)+)/gm, function (wholeMatch, m1) {
var bq = m1;

// attacklab: hack around Konqueror 3.5.4 bug:
Expand Down
9 changes: 9 additions & 0 deletions test/cases/blockquote-followed-by-code.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<blockquote>
<p>a blockquote with a 4 space indented line (not code)</p>
</blockquote>
<p>sep</p>
<blockquote>
<p>a blockquote</p>
</blockquote>
<pre><code>with some code after
</code></pre>
8 changes: 8 additions & 0 deletions test/cases/blockquote-followed-by-code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
> a blockquote
with a 4 space indented line (not code)

sep

> a blockquote
with some code after
8 changes: 8 additions & 0 deletions test/cases/blockquote-inside-code.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<pre><code>&gt; this is a pseudo blockquote
&gt; inside a code block
</code></pre>

<p>foo</p>
<pre><code>&gt; this is another bq
inside code
</code></pre>
7 changes: 7 additions & 0 deletions test/cases/blockquote-inside-code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
> this is a pseudo blockquote
> inside a code block

foo

> this is another bq
inside code
4 changes: 4 additions & 0 deletions test/issues/#191.blockquote-followed-by-an-heading.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<blockquote>
<p>a blockquote</p>
<h1 id="followedbyanheading">followed by an heading</h1>
</blockquote>
2 changes: 2 additions & 0 deletions test/issues/#191.blockquote-followed-by-an-heading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> a blockquote
# followed by an heading

0 comments on commit 3df7062

Please sign in to comment.