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
This commit is contained in:
Estevao Soares dos Santos 2017-12-22 09:54:23 +00:00
parent 9825fd2bd0
commit ea3db5f180
9 changed files with 58 additions and 5 deletions

View File

@ -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.

View File

@ -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) {

View File

@ -33,7 +33,8 @@ var showdown = {},
ghCompatibleHeaderId: true,
ghMentions: true,
backslashEscapesHTMLTags: true,
emoji: true
emoji: true,
splitAdjacentBlockquotes: true
},
original: {
noHeaderId: true,

View File

@ -3,12 +3,19 @@ showdown.subParser('makehtml.blockQuotes', function (text, options, globals) {
text = globals.converter._dispatch('makehtml.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, '');

View File

@ -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>

View File

@ -0,0 +1,7 @@
> # Block quote 1
>
> This is my first block quote.
> # Block quote 2
>
> This is my second block quote.

View File

@ -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>

View File

@ -0,0 +1,5 @@
> This is my second block quote
yeah
everythong is ok.
This is not a blockquote

View File

@ -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';
@ -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));
}
});
});