Skip to content

Commit

Permalink
feat(splitAdjacentBlockquotes): add option to split adjacent blockquo…
Browse files Browse the repository at this point in the history
…te 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
  • Loading branch information
tivie committed Dec 22, 2017
1 parent c9727e2 commit da328f2
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 14 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ var defaultOptions = showdown.getDefaultOptions();
* **metadata**: (boolean) [default false] Enable support for document metadata (defined at the top of the document
between `«««` and `»»»` or between `---` and `---`). (since v.1.8.5)
* **splitAdjacentBlockquotes**: (boolean) [default false] Split adjacent blockquote blocks.(since v.1.8.6)
**NOTE**: Please note that until **version 1.6.0**, all of these options are ***DISABLED*** by default in the cli tool.
Expand Down
23 changes: 18 additions & 5 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.

5 changes: 5 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ function getDefaultOpts (simple) {
defaultValue: false,
description: 'Enable support for document metadata (defined at the top of the document between `«««` and `»»»` or between `---` and `---`).',
type: 'boolean'
},
splitAdjacentBlockquotes: {
defaultValue: false,
description: 'Split adjacent blockquote blocks',
type: 'boolean'
}
};
if (simple === false) {
Expand Down
3 changes: 2 additions & 1 deletion src/showdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ var showdown = {},
ghCompatibleHeaderId: true,
ghMentions: true,
backslashEscapesHTMLTags: true,
emoji: true
emoji: true,
splitAdjacentBlockquotes: true
},
original: {
noHeaderId: true,
Expand Down
13 changes: 10 additions & 3 deletions src/subParsers/blockQuotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ showdown.subParser('blockQuotes', function (text, options, globals) {

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

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

var rgx = /(^ {0,3}>[ \t]?.+\n(.+\n)*\n*)+/gm;

if (options.splitAdjacentBlockquotes) {
rgx = /^ {0,3}>[\s\S]*?(?:\n\n)/gm;
}

text = text.replace(rgx, function (bq) {
// attacklab: hack around Konqueror 3.5.4 bug:
// "----------bug".replace(/^-/g,"") == "bug"
bq = bq.replace(/^[ \t]*>[ \t]?/gm, '¨0'); // trim one level of quoting
bq = bq.replace(/^[ \t]*>[ \t]?/gm, ''); // trim one level of quoting

// attacklab: clean up hack
bq = bq.replace(/¨0/g, '');
Expand Down
8 changes: 8 additions & 0 deletions test/features/splitAdjacentBlockquotes/basic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<blockquote>
<h1 id="blockquote1">Block quote 1</h1>
<p>This is my first block quote.</p>
</blockquote>
<blockquote>
<h1 id="blockquote2">Block quote 2</h1>
<p>This is my second block quote.</p>
</blockquote>
7 changes: 7 additions & 0 deletions test/features/splitAdjacentBlockquotes/basic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
> # Block quote 1
>
> This is my first block quote.
> # Block quote 2
>
> This is my second block quote.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<blockquote>
<p>This is my second block quote
yeah
everythong is ok.</p>
</blockquote>
<p>This is not a blockquote</p>
5 changes: 5 additions & 0 deletions test/features/splitAdjacentBlockquotes/multiline-paragraph.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
> This is my second block quote
yeah
everythong is ok.

This is not a blockquote
14 changes: 13 additions & 1 deletion test/node/testsuite.features.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ var bootstrap = require('../bootstrap.js'),
literalMidWordUnderscoresSuite = bootstrap.getTestSuite('test/features/literalMidWordUnderscores/'),
literalMidWordAsterisksSuite = bootstrap.getTestSuite('test/features/literalMidWordAsterisks/'),
completeHTMLOutputSuite = bootstrap.getTestSuite('test/features/completeHTMLOutput/'),
metadataSuite = bootstrap.getTestSuite('test/features/metadata/');
metadataSuite = bootstrap.getTestSuite('test/features/metadata/'),
splitAdjacentBlockquotesSuite = bootstrap.getTestSuite('test/features/splitAdjacentBlockquotes/');

describe('makeHtml() features testsuite', function () {
'use strict';
Expand Down Expand Up @@ -264,4 +265,15 @@ describe('makeHtml() features testsuite', function () {
it(suite[i].name.replace(/-/g, ' '), assertion(suite[i], converter));
}
});

/** test metadata option **/
describe('splitAdjacentBlockquotes option', function () {
var converter,
suite = splitAdjacentBlockquotesSuite;

for (var i = 0; i < suite.length; ++i) {
converter = new showdown.Converter({splitAdjacentBlockquotes: true});
it(suite[i].name.replace(/-/g, ' '), assertion(suite[i], converter));
}
});
});

0 comments on commit da328f2

Please sign in to comment.