Skip to content

Commit

Permalink
feat(disableForced4SpacesIndentedSublists): option that disables the …
Browse files Browse the repository at this point in the history
…requirement of indenting nested sublists by 4 spaces
  • Loading branch information
tivie committed Nov 11, 2016
1 parent 1a232e8 commit 0be39bc
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 33 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -347,14 +350,14 @@ PRs are awesome. However, before you submit your pull request consider the follo
- We use commit notes to generate the changelog. It's extremely helpful if your commit messages adhere to the
[**AngularJS Git Commit Guidelines**][ng-commit-guide].
- If we suggest changes then:
- Make the required updates.
- Re-run the Angular test suite to ensure tests are still passing.
- Rebase your branch and force push to your GitHub repository (this will update your Pull Request):
```bash
git rebase master -i
git push origin my-fix-branch -f
```
- Make the required updates.
- Re-run the Angular test suite to ensure tests are still passing.
- Rebase your branch and force push to your GitHub repository (this will update your Pull Request):
```bash
git rebase master -i
git push origin my-fix-branch -f
```
- After your pull request is merged, you can safely delete your branch.
If you have time to contribute to this project, we feel obliged that you get credit for it.
Expand Down
35 changes: 24 additions & 11 deletions dist/showdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 10 additions & 9 deletions src/showdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ var showdown = {},
globalOptions = getDefaultOpts(true),
flavor = {
github: {
omitExtraWLInCodeBlocks: true,
prefixHeaderId: 'user-content-',
simplifiedAutoLink: true,
literalMidWordUnderscores: true,
strikethrough: true,
tables: true,
tablesHeaderId: true,
ghCodeBlocks: true,
tasklists: true
omitExtraWLInCodeBlocks: true,
prefixHeaderId: 'user-content-',
simplifiedAutoLink: true,
literalMidWordUnderscores: true,
strikethrough: true,
tables: true,
tablesHeaderId: true,
ghCodeBlocks: true,
tasklists: true,
disableForced4SpacesIndentedSublists: true
},
vanilla: getDefaultOpts(true)
};
Expand Down
11 changes: 9 additions & 2 deletions src/subParsers/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() !== '');

Expand Down Expand Up @@ -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 = '';

Expand Down
13 changes: 13 additions & 0 deletions test/features/disableForced4SpacesIndentedSublists.html
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions test/features/disableForced4SpacesIndentedSublists.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
* foo
* bar

...

* baz
1. bazinga
2 changes: 2 additions & 0 deletions test/node/testsuite.features.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 0be39bc

Please sign in to comment.