Pārlūkot izejas kodu

feat(smart-indent-fix): fix for es6 identation problems

Closes #259
Estevão Soares dos Santos 9 gadi atpakaļ
vecāks
revīzija
261f127f7e

+ 2 - 0
README.md

@@ -251,6 +251,8 @@ var defaultOptions = showdown.getDefaultOptions();
     - [ ] This is still pending
    ```
  * **smoothLivePreview**: (boolean) [default false] Prevents weird effects in live previews due to incomplete input
+ 
+ * **smartIndentationFix**: (boolean) [default false] Tries to smartly fix indentation problems related to es6 template strings in the midst of indented code.
 
 ## CLI Tool
 

+ 17 - 2
dist/showdown.js

@@ -1,4 +1,4 @@
-;/*! showdown 13-05-2016 */
+;/*! showdown 07-06-2016 */
 (function(){
 /**
  * Created by Tivie on 13-07-2015.
@@ -72,6 +72,11 @@ function getDefaultOpts(simple) {
       default: false,
       describe: 'Prevents weird effects in live previews due to incomplete input',
       type: 'boolean'
+    },
+    smartIndentationFix: {
+      default: false,
+      description: 'Tries to smartly fix identation in es6 strings',
+      type: 'boolean'
     }
   };
   if (simple === false) {
@@ -876,6 +881,12 @@ showdown.Converter = function (converterOptions) {
     listeners[name].push(callback);
   }
 
+  function rTrimInputText(text) {
+    var rsp = text.match(/^\s*/)[0].length,
+        rgx = new RegExp('^\\s{0,' + rsp + '}', 'gm');
+    return text.replace(rgx, '');
+  }
+
   /**
    * Dispatch an event
    * @private
@@ -949,6 +960,10 @@ showdown.Converter = function (converterOptions) {
     text = text.replace(/\r\n/g, '\n'); // DOS to Unix
     text = text.replace(/\r/g, '\n'); // Mac to Unix
 
+    if (options.smartIndentationFix) {
+      text = rTrimInputText(text);
+    }
+
     // Make sure text begins and ends with a couple of newlines:
     text = '\n\n' + text + '\n\n';
 
@@ -2517,4 +2532,4 @@ if (typeof module !== 'undefined' && module.exports) {
 }
 }).call(this);
 
-//# sourceMappingURL=showdown.js.map
+//# sourceMappingURL=showdown.js.map

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


+ 10 - 0
src/converter.js

@@ -189,6 +189,12 @@ showdown.Converter = function (converterOptions) {
     listeners[name].push(callback);
   }
 
+  function rTrimInputText(text) {
+    var rsp = text.match(/^\s*/)[0].length,
+        rgx = new RegExp('^\\s{0,' + rsp + '}', 'gm');
+    return text.replace(rgx, '');
+  }
+
   /**
    * Dispatch an event
    * @private
@@ -262,6 +268,10 @@ showdown.Converter = function (converterOptions) {
     text = text.replace(/\r\n/g, '\n'); // DOS to Unix
     text = text.replace(/\r/g, '\n'); // Mac to Unix
 
+    if (options.smartIndentationFix) {
+      text = rTrimInputText(text);
+    }
+
     // Make sure text begins and ends with a couple of newlines:
     text = '\n\n' + text + '\n\n';
 

+ 5 - 0
src/options.js

@@ -70,6 +70,11 @@ function getDefaultOpts(simple) {
       default: false,
       describe: 'Prevents weird effects in live previews due to incomplete input',
       type: 'boolean'
+    },
+    smartIndentationFix: {
+      default: false,
+      description: 'Tries to smartly fix identation in es6 strings',
+      type: 'boolean'
     }
   };
   if (simple === false) {

+ 9 - 0
test/features/#259.es6-template-strings-indentation-issues.html

@@ -0,0 +1,9 @@
+<h2 id="markdowndoc">markdown doc</h2>
+
+<p>you can use markdown for card documentation</p>
+
+<ul>
+    <li>foo</li>
+
+    <li>bar</li>
+</ul>

+ 5 - 0
test/features/#259.es6-template-strings-indentation-issues.md

@@ -0,0 +1,5 @@
+      ## markdown doc
+      
+      you can use markdown for card documentation
+        - foo
+        - bar

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

@@ -29,6 +29,8 @@ describe('makeHtml() features testsuite', function () {
       converter = new showdown.Converter({literalMidWordUnderscores: true, simplifiedAutoLink: true});
     } else if (testsuite[i].name === '#198.literalMidWordUnderscores-changes-behavior-of-asterisk') {
       converter = new showdown.Converter({literalMidWordUnderscores: true});
+    } else if (testsuite[i].name === '#259.es6-template-strings-indentation-issues') {
+      converter = new showdown.Converter({smartIndentationFix: true});
     } else {
       converter = new showdown.Converter();
     }

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