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
17
README.md
17
README.md
|
@ -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
|
||||
|
@ -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):
|
||||
- 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
|
||||
```
|
||||
```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.
|
||||
|
|
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) {
|
||||
|
|
|
@ -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)
|
||||
};
|
||||
|
|
|
@ -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