feat(disableForced4SpacesIndentedSublists): option that disables the requirement of indenting nested sublists by 4 spaces

This commit is contained in:
Estevao Soares dos Santos 2016-11-11 08:15:24 +00:00
parent 1a232e8717
commit 0be39bccae
11 changed files with 56 additions and 18 deletions

View File

@ -260,6 +260,9 @@ var defaultOptions = showdown.getDefaultOptions();
* **smartIndentationFix**: (boolean) [default false] Tries to smartly fix indentation problems related to es6 template strings in the midst of indented code. * **smartIndentationFix**: (boolean) [default false] Tries to smartly fix indentation problems related to es6 template strings in the midst of indented code.
* **disableForced4SpacesIndentedSublists**: (boolean) [default false] Disables the requirement of indenting sublists by 4 spaces for them to be nested,
effectively reverting to the old behavior where 2 or 3 spaces were enough. (since v1.5.0)
## CLI Tool ## CLI Tool
Showdown also comes bundled with a Command Line Interface tool. You can check the [CLI wiki page][cli-wiki] for more info Showdown also comes bundled with a Command Line Interface tool. You can check the [CLI wiki page][cli-wiki] for more info

BIN
dist/showdown.js vendored

Binary file not shown.

BIN
dist/showdown.js.map vendored

Binary file not shown.

BIN
dist/showdown.min.js vendored

Binary file not shown.

Binary file not shown.

View File

@ -75,6 +75,11 @@ function getDefaultOpts(simple) {
defaultValue: false, defaultValue: false,
description: 'Tries to smartly fix indentation in es6 strings', description: 'Tries to smartly fix indentation in es6 strings',
type: 'boolean' type: 'boolean'
},
disableForced4SpacesIndentedSublists: {
defaultValue: false,
description: 'Disables the requirement of indenting nested sublists by 4 spaces',
type: 'boolean'
} }
}; };
if (simple === false) { if (simple === false) {

View File

@ -17,7 +17,8 @@ var showdown = {},
tables: true, tables: true,
tablesHeaderId: true, tablesHeaderId: true,
ghCodeBlocks: true, ghCodeBlocks: true,
tasklists: true tasklists: true,
disableForced4SpacesIndentedSublists: true
}, },
vanilla: getDefaultOpts(true) vanilla: getDefaultOpts(true)
}; };

View File

@ -44,6 +44,13 @@ showdown.subParser('lists', function (text, options, globals) {
var rgx = /(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(~0| {0,3}([*+-]|\d+[.])[ \t]+))/gm, var rgx = /(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(~0| {0,3}([*+-]|\d+[.])[ \t]+))/gm,
isParagraphed = (/\n[ \t]*\n(?!~0)/.test(listStr)); isParagraphed = (/\n[ \t]*\n(?!~0)/.test(listStr));
// Since version 1.5, nesting sublists requires 4 spaces (or 1 tab) indentation,
// which is a syntax breaking change
// activating this option reverts to old behavior
if (options.disableForced4SpacesIndentedSublists) {
rgx = /(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(~0|\2([*+-]|\d+[.])[ \t]+))/gm;
}
listStr = listStr.replace(rgx, function (wholeMatch, m1, m2, m3, m4, taskbtn, checked) { listStr = listStr.replace(rgx, function (wholeMatch, m1, m2, m3, m4, taskbtn, checked) {
checked = (checked && checked.trim() !== ''); checked = (checked && checked.trim() !== '');
@ -105,8 +112,8 @@ showdown.subParser('lists', function (text, options, globals) {
function parseConsecutiveLists(list, listType, trimTrailing) { function parseConsecutiveLists(list, listType, trimTrailing) {
// check if we caught 2 or more consecutive lists by mistake // check if we caught 2 or more consecutive lists by mistake
// we use the counterRgx, meaning if listType is UL we look for OL and vice versa // we use the counterRgx, meaning if listType is UL we look for OL and vice versa
var olRgx = /^ {0,3}\d+\.[ \t]/gm, var olRgx = (options.disableForced4SpacesIndentedSublists) ? /^ ?\d+\.[ \t]/gm : /^ {0,3}\d+\.[ \t]/gm,
ulRgx = /^ {0,3}[*+-][ \t]/gm, ulRgx = (options.disableForced4SpacesIndentedSublists) ? /^ ?[*+-][ \t]/gm : /^ {0,3}[*+-][ \t]/gm,
counterRxg = (listType === 'ul') ? olRgx : ulRgx, counterRxg = (listType === 'ul') ? olRgx : ulRgx,
result = ''; result = '';

View File

@ -0,0 +1,13 @@
<ul>
<li>foo
<ul>
<li>bar</li></ul></li>
</ul>
<p>...</p>
<ul>
<li>baz
<ol>
<li>bazinga</li></ol></li>
</ul>

View File

@ -0,0 +1,7 @@
* foo
* bar
...
* baz
1. bazinga

View File

@ -33,6 +33,8 @@ describe('makeHtml() features testsuite', function () {
converter = new showdown.Converter({smartIndentationFix: true}); converter = new showdown.Converter({smartIndentationFix: true});
} else if (testsuite[i].name === '#284.simplifiedAutoLink-does-not-match-GFM-style') { } else if (testsuite[i].name === '#284.simplifiedAutoLink-does-not-match-GFM-style') {
converter = new showdown.Converter({simplifiedAutoLink: true}); converter = new showdown.Converter({simplifiedAutoLink: true});
} else if (testsuite[i].name === 'disableForced4SpacesIndentedSublists') {
converter = new showdown.Converter({disableForced4SpacesIndentedSublists: true});
} else { } else {
converter = new showdown.Converter(); converter = new showdown.Converter();
} }