Skip to content

Commit da328f2

Browse files
committed
feat(splitAdjacentBlockquotes): add option to split adjacent blockquote blocks
With this option enabled, this: ```md > some text > some other text ``` witll result in: ```html <blockquote> <p>some text</p> </blockquote> <blockquote> <p>some other text</p> </blockquote> ``` This is the default behavior of GFM. Closes #477
1 parent c9727e2 commit da328f2

File tree

13 files changed

+80
-14
lines changed

13 files changed

+80
-14
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ var defaultOptions = showdown.getDefaultOptions();
366366
* **metadata**: (boolean) [default false] Enable support for document metadata (defined at the top of the document
367367
between `«««` and `»»»` or between `---` and `---`). (since v.1.8.5)
368368
369+
* **splitAdjacentBlockquotes**: (boolean) [default false] Split adjacent blockquote blocks.(since v.1.8.6)
370+
369371
**NOTE**: Please note that until **version 1.6.0**, all of these options are ***DISABLED*** by default in the cli tool.
370372
371373

dist/showdown.js

Lines changed: 18 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/options.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ function getDefaultOpts (simple) {
160160
defaultValue: false,
161161
description: 'Enable support for document metadata (defined at the top of the document between `«««` and `»»»` or between `---` and `---`).',
162162
type: 'boolean'
163+
},
164+
splitAdjacentBlockquotes: {
165+
defaultValue: false,
166+
description: 'Split adjacent blockquote blocks',
167+
type: 'boolean'
163168
}
164169
};
165170
if (simple === false) {

src/showdown.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ var showdown = {},
2525
ghCompatibleHeaderId: true,
2626
ghMentions: true,
2727
backslashEscapesHTMLTags: true,
28-
emoji: true
28+
emoji: true,
29+
splitAdjacentBlockquotes: true
2930
},
3031
original: {
3132
noHeaderId: true,

src/subParsers/blockQuotes.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@ showdown.subParser('blockQuotes', function (text, options, globals) {
33

44
text = globals.converter._dispatch('blockQuotes.before', text, options, globals);
55

6-
text = text.replace(/((^ {0,3}>[ \t]?.+\n(.+\n)*\n*)+)/gm, function (wholeMatch, m1) {
7-
var bq = m1;
6+
// add a couple extra lines after the text and endtext mark
7+
text = text + '\n\n';
88

9+
var rgx = /(^ {0,3}>[ \t]?.+\n(.+\n)*\n*)+/gm;
10+
11+
if (options.splitAdjacentBlockquotes) {
12+
rgx = /^ {0,3}>[\s\S]*?(?:\n\n)/gm;
13+
}
14+
15+
text = text.replace(rgx, function (bq) {
916
// attacklab: hack around Konqueror 3.5.4 bug:
1017
// "----------bug".replace(/^-/g,"") == "bug"
11-
bq = bq.replace(/^[ \t]*>[ \t]?/gm, '¨0'); // trim one level of quoting
18+
bq = bq.replace(/^[ \t]*>[ \t]?/gm, ''); // trim one level of quoting
1219

1320
// attacklab: clean up hack
1421
bq = bq.replace(/¨0/g, '');
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<blockquote>
2+
<h1 id="blockquote1">Block quote 1</h1>
3+
<p>This is my first block quote.</p>
4+
</blockquote>
5+
<blockquote>
6+
<h1 id="blockquote2">Block quote 2</h1>
7+
<p>This is my second block quote.</p>
8+
</blockquote>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
> # Block quote 1
2+
>
3+
> This is my first block quote.
4+
5+
> # Block quote 2
6+
>
7+
> This is my second block quote.

0 commit comments

Comments
 (0)