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

Closes #259
This commit is contained in:
Estevão Soares dos Santos 2016-06-07 01:23:52 +01:00
parent e586201025
commit 261f127f7e
8 changed files with 33 additions and 0 deletions

View File

@ -251,6 +251,8 @@ var defaultOptions = showdown.getDefaultOptions();
- [ ] This is still pending - [ ] This is still pending
``` ```
* **smoothLivePreview**: (boolean) [default false] Prevents weird effects in live previews due to incomplete input * **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 ## CLI Tool

BIN
dist/showdown.js vendored

Binary file not shown.

BIN
dist/showdown.js.map vendored

Binary file not shown.

View File

@ -189,6 +189,12 @@ showdown.Converter = function (converterOptions) {
listeners[name].push(callback); 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 * Dispatch an event
* @private * @private
@ -262,6 +268,10 @@ showdown.Converter = function (converterOptions) {
text = text.replace(/\r\n/g, '\n'); // DOS to Unix text = text.replace(/\r\n/g, '\n'); // DOS to Unix
text = text.replace(/\r/g, '\n'); // Mac 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: // Make sure text begins and ends with a couple of newlines:
text = '\n\n' + text + '\n\n'; text = '\n\n' + text + '\n\n';

View File

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

View File

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

View File

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

View File

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