diff --git a/README.md b/README.md index 9722040..602da58 100644 --- a/README.md +++ b/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 diff --git a/dist/showdown.js b/dist/showdown.js index 4cc545c..d6f237b 100644 Binary files a/dist/showdown.js and b/dist/showdown.js differ diff --git a/dist/showdown.js.map b/dist/showdown.js.map index e198249..cc77c58 100644 Binary files a/dist/showdown.js.map and b/dist/showdown.js.map differ diff --git a/src/converter.js b/src/converter.js index 63180ac..9a0c391 100644 --- a/src/converter.js +++ b/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'; diff --git a/src/options.js b/src/options.js index 9364938..2cfaf42 100644 --- a/src/options.js +++ b/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) { diff --git a/test/features/#259.es6-template-strings-indentation-issues.html b/test/features/#259.es6-template-strings-indentation-issues.html new file mode 100644 index 0000000..b37048e --- /dev/null +++ b/test/features/#259.es6-template-strings-indentation-issues.html @@ -0,0 +1,9 @@ +

markdown doc

+ +

you can use markdown for card documentation

+ + diff --git a/test/features/#259.es6-template-strings-indentation-issues.md b/test/features/#259.es6-template-strings-indentation-issues.md new file mode 100644 index 0000000..c8f77b6 --- /dev/null +++ b/test/features/#259.es6-template-strings-indentation-issues.md @@ -0,0 +1,5 @@ + ## markdown doc + + you can use markdown for card documentation + - foo + - bar diff --git a/test/node/testsuite.features.js b/test/node/testsuite.features.js index 5b250d8..049d3b1 100644 --- a/test/node/testsuite.features.js +++ b/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(); }