mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
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:
parent
9825fd2bd0
commit
ea3db5f180
|
@ -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.
|
||||
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -33,7 +33,8 @@ var showdown = {},
|
|||
ghCompatibleHeaderId: true,
|
||||
ghMentions: true,
|
||||
backslashEscapesHTMLTags: true,
|
||||
emoji: true
|
||||
emoji: true,
|
||||
splitAdjacentBlockquotes: true
|
||||
},
|
||||
original: {
|
||||
noHeaderId: true,
|
||||
|
|
|
@ -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, '');
|
||||
|
|
8
test/features/splitAdjacentBlockquotes/basic.html
Normal file
8
test/features/splitAdjacentBlockquotes/basic.html
Normal 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>
|
7
test/features/splitAdjacentBlockquotes/basic.md
Normal file
7
test/features/splitAdjacentBlockquotes/basic.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
> # Block quote 1
|
||||
>
|
||||
> This is my first block quote.
|
||||
|
||||
> # Block quote 2
|
||||
>
|
||||
> This is my second block quote.
|
|
@ -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>
|
|
@ -0,0 +1,5 @@
|
|||
> This is my second block quote
|
||||
yeah
|
||||
everythong is ok.
|
||||
|
||||
This is not a blockquote
|
|
@ -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));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user