Skip to content

Commit 0be39bc

Browse files
committed
feat(disableForced4SpacesIndentedSublists): option that disables the requirement of indenting nested sublists by 4 spaces
1 parent 1a232e8 commit 0be39bc

11 files changed

+84
-33
lines changed

README.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ var defaultOptions = showdown.getDefaultOptions();
260260
261261
* **smartIndentationFix**: (boolean) [default false] Tries to smartly fix indentation problems related to es6 template strings in the midst of indented code.
262262
263+
* **disableForced4SpacesIndentedSublists**: (boolean) [default false] Disables the requirement of indenting sublists by 4 spaces for them to be nested,
264+
effectively reverting to the old behavior where 2 or 3 spaces were enough. (since v1.5.0)
265+
263266
## CLI Tool
264267
265268
Showdown also comes bundled with a Command Line Interface tool. You can check the [CLI wiki page][cli-wiki] for more info
@@ -347,14 +350,14 @@ PRs are awesome. However, before you submit your pull request consider the follo
347350
- We use commit notes to generate the changelog. It's extremely helpful if your commit messages adhere to the
348351
[**AngularJS Git Commit Guidelines**][ng-commit-guide].
349352
- If we suggest changes then:
350-
- Make the required updates.
351-
- Re-run the Angular test suite to ensure tests are still passing.
352-
- Rebase your branch and force push to your GitHub repository (this will update your Pull Request):
353-
354-
```bash
355-
git rebase master -i
356-
git push origin my-fix-branch -f
357-
```
353+
- Make the required updates.
354+
- Re-run the Angular test suite to ensure tests are still passing.
355+
- Rebase your branch and force push to your GitHub repository (this will update your Pull Request):
356+
357+
```bash
358+
git rebase master -i
359+
git push origin my-fix-branch -f
360+
```
358361
- After your pull request is merged, you can safely delete your branch.
359362
360363
If you have time to contribute to this project, we feel obliged that you get credit for it.

dist/showdown.js

+24-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/options.js

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ function getDefaultOpts(simple) {
7575
defaultValue: false,
7676
description: 'Tries to smartly fix indentation in es6 strings',
7777
type: 'boolean'
78+
},
79+
disableForced4SpacesIndentedSublists: {
80+
defaultValue: false,
81+
description: 'Disables the requirement of indenting nested sublists by 4 spaces',
82+
type: 'boolean'
7883
}
7984
};
8085
if (simple === false) {

src/showdown.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ var showdown = {},
99
globalOptions = getDefaultOpts(true),
1010
flavor = {
1111
github: {
12-
omitExtraWLInCodeBlocks: true,
13-
prefixHeaderId: 'user-content-',
14-
simplifiedAutoLink: true,
15-
literalMidWordUnderscores: true,
16-
strikethrough: true,
17-
tables: true,
18-
tablesHeaderId: true,
19-
ghCodeBlocks: true,
20-
tasklists: true
12+
omitExtraWLInCodeBlocks: true,
13+
prefixHeaderId: 'user-content-',
14+
simplifiedAutoLink: true,
15+
literalMidWordUnderscores: true,
16+
strikethrough: true,
17+
tables: true,
18+
tablesHeaderId: true,
19+
ghCodeBlocks: true,
20+
tasklists: true,
21+
disableForced4SpacesIndentedSublists: true
2122
},
2223
vanilla: getDefaultOpts(true)
2324
};

src/subParsers/lists.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ showdown.subParser('lists', function (text, options, globals) {
4444
var rgx = /(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(~0| {0,3}([*+-]|\d+[.])[ \t]+))/gm,
4545
isParagraphed = (/\n[ \t]*\n(?!~0)/.test(listStr));
4646

47+
// Since version 1.5, nesting sublists requires 4 spaces (or 1 tab) indentation,
48+
// which is a syntax breaking change
49+
// activating this option reverts to old behavior
50+
if (options.disableForced4SpacesIndentedSublists) {
51+
rgx = /(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(~0|\2([*+-]|\d+[.])[ \t]+))/gm;
52+
}
53+
4754
listStr = listStr.replace(rgx, function (wholeMatch, m1, m2, m3, m4, taskbtn, checked) {
4855
checked = (checked && checked.trim() !== '');
4956

@@ -105,8 +112,8 @@ showdown.subParser('lists', function (text, options, globals) {
105112
function parseConsecutiveLists(list, listType, trimTrailing) {
106113
// check if we caught 2 or more consecutive lists by mistake
107114
// we use the counterRgx, meaning if listType is UL we look for OL and vice versa
108-
var olRgx = /^ {0,3}\d+\.[ \t]/gm,
109-
ulRgx = /^ {0,3}[*+-][ \t]/gm,
115+
var olRgx = (options.disableForced4SpacesIndentedSublists) ? /^ ?\d+\.[ \t]/gm : /^ {0,3}\d+\.[ \t]/gm,
116+
ulRgx = (options.disableForced4SpacesIndentedSublists) ? /^ ?[*+-][ \t]/gm : /^ {0,3}[*+-][ \t]/gm,
110117
counterRxg = (listType === 'ul') ? olRgx : ulRgx,
111118
result = '';
112119

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<ul>
2+
<li>foo
3+
4+
<ul>
5+
<li>bar</li></ul></li>
6+
</ul>
7+
<p>...</p>
8+
<ul>
9+
<li>baz
10+
11+
<ol>
12+
<li>bazinga</li></ol></li>
13+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
* foo
2+
* bar
3+
4+
...
5+
6+
* baz
7+
1. bazinga

test/node/testsuite.features.js

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ describe('makeHtml() features testsuite', function () {
3333
converter = new showdown.Converter({smartIndentationFix: true});
3434
} else if (testsuite[i].name === '#284.simplifiedAutoLink-does-not-match-GFM-style') {
3535
converter = new showdown.Converter({simplifiedAutoLink: true});
36+
} else if (testsuite[i].name === 'disableForced4SpacesIndentedSublists') {
37+
converter = new showdown.Converter({disableForced4SpacesIndentedSublists: true});
3638
} else {
3739
converter = new showdown.Converter();
3840
}

0 commit comments

Comments
 (0)