mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
feat(disableForced4SpacesIndentedSublists): option that disables the requirement of indenting nested sublists by 4 spaces
This commit is contained in:
parent
1a232e8717
commit
0be39bccae
|
@ -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.
|
||||
|
||||
* **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
|
||||
|
||||
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
BIN
dist/showdown.js
vendored
Binary file not shown.
BIN
dist/showdown.js.map
vendored
BIN
dist/showdown.js.map
vendored
Binary file not shown.
BIN
dist/showdown.min.js
vendored
BIN
dist/showdown.min.js
vendored
Binary file not shown.
BIN
dist/showdown.min.js.map
vendored
BIN
dist/showdown.min.js.map
vendored
Binary file not shown.
|
@ -75,6 +75,11 @@ function getDefaultOpts(simple) {
|
|||
defaultValue: false,
|
||||
description: 'Tries to smartly fix indentation in es6 strings',
|
||||
type: 'boolean'
|
||||
},
|
||||
disableForced4SpacesIndentedSublists: {
|
||||
defaultValue: false,
|
||||
description: 'Disables the requirement of indenting nested sublists by 4 spaces',
|
||||
type: 'boolean'
|
||||
}
|
||||
};
|
||||
if (simple === false) {
|
||||
|
|
|
@ -17,7 +17,8 @@ var showdown = {},
|
|||
tables: true,
|
||||
tablesHeaderId: true,
|
||||
ghCodeBlocks: true,
|
||||
tasklists: true
|
||||
tasklists: true,
|
||||
disableForced4SpacesIndentedSublists: true
|
||||
},
|
||||
vanilla: getDefaultOpts(true)
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
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) {
|
||||
checked = (checked && checked.trim() !== '');
|
||||
|
||||
|
@ -105,8 +112,8 @@ showdown.subParser('lists', function (text, options, globals) {
|
|||
function parseConsecutiveLists(list, listType, trimTrailing) {
|
||||
// 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
|
||||
var olRgx = /^ {0,3}\d+\.[ \t]/gm,
|
||||
ulRgx = /^ {0,3}[*+-][ \t]/gm,
|
||||
var olRgx = (options.disableForced4SpacesIndentedSublists) ? /^ ?\d+\.[ \t]/gm : /^ {0,3}\d+\.[ \t]/gm,
|
||||
ulRgx = (options.disableForced4SpacesIndentedSublists) ? /^ ?[*+-][ \t]/gm : /^ {0,3}[*+-][ \t]/gm,
|
||||
counterRxg = (listType === 'ul') ? olRgx : ulRgx,
|
||||
result = '';
|
||||
|
||||
|
|
13
test/features/disableForced4SpacesIndentedSublists.html
Normal file
13
test/features/disableForced4SpacesIndentedSublists.html
Normal 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>
|
7
test/features/disableForced4SpacesIndentedSublists.md
Normal file
7
test/features/disableForced4SpacesIndentedSublists.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
* foo
|
||||
* bar
|
||||
|
||||
...
|
||||
|
||||
* baz
|
||||
1. bazinga
|
|
@ -33,6 +33,8 @@ describe('makeHtml() features testsuite', function () {
|
|||
converter = new showdown.Converter({smartIndentationFix: true});
|
||||
} else if (testsuite[i].name === '#284.simplifiedAutoLink-does-not-match-GFM-style') {
|
||||
converter = new showdown.Converter({simplifiedAutoLink: true});
|
||||
} else if (testsuite[i].name === 'disableForced4SpacesIndentedSublists') {
|
||||
converter = new showdown.Converter({disableForced4SpacesIndentedSublists: true});
|
||||
} else {
|
||||
converter = new showdown.Converter();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user