Pārlūkot izejas kodu

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

Estevao Soares dos Santos 8 gadi atpakaļ
vecāks
revīzija
0be39bccae

+ 11 - 8
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.
  * **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
@@ -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
  - 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].
  [**AngularJS Git Commit Guidelines**][ng-commit-guide].
  - If we suggest changes then:
  - 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.
  - 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.
 If you have time to contribute to this project, we feel obliged that you get credit for it.

+ 24 - 11
dist/showdown.js

@@ -77,6 +77,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) {
@@ -102,15 +107,16 @@ var showdown = {},
     globalOptions = getDefaultOpts(true),
     globalOptions = getDefaultOpts(true),
     flavor = {
     flavor = {
       github: {
       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)
       vanilla: getDefaultOpts(true)
     };
     };
@@ -1954,6 +1960,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() !== '');
 
 
@@ -2015,8 +2028,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,
-        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,
         counterRxg = (listType === 'ul') ? olRgx : ulRgx,
         result = '';
         result = '';
 
 

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/showdown.js.map


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/showdown.min.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/showdown.min.js.map


+ 5 - 0
src/options.js

@@ -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) {

+ 10 - 9
src/showdown.js

@@ -9,15 +9,16 @@ var showdown = {},
     globalOptions = getDefaultOpts(true),
     globalOptions = getDefaultOpts(true),
     flavor = {
     flavor = {
       github: {
       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)
       vanilla: getDefaultOpts(true)
     };
     };

+ 9 - 2
src/subParsers/lists.js

@@ -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,
-        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,
         counterRxg = (listType === 'ul') ? olRgx : ulRgx,
         result = '';
         result = '';
 
 

+ 13 - 0
test/features/disableForced4SpacesIndentedSublists.html

@@ -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 - 0
test/features/disableForced4SpacesIndentedSublists.md

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

+ 2 - 0
test/node/testsuite.features.js

@@ -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();
     }
     }

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels