summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorjeremyfa <jeremy.faivre@gmail.com>2015-05-22 00:45:04 +0200
committerjeremyfa <jeremy.faivre@gmail.com>2015-05-22 00:45:04 +0200
commitd45e07527d0ad342d87fa030eafd45cfb7421a16 (patch)
treea8ae0944085149f90281bf8e553408d147ff682a /lib
parentc3bffaa47151d2ae8ec8a1b5ef98602c94cd55c7 (diff)
downloadyamljs-d45e07527d0ad342d87fa030eafd45cfb7421a16.tar.gz
Fix #12 and add related unit test
Diffstat (limited to 'lib')
-rw-r--r--lib/Parser.js18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/Parser.js b/lib/Parser.js
index 3a8ae74..d62dd7f 100644
--- a/lib/Parser.js
+++ b/lib/Parser.js
@@ -528,7 +528,7 @@ Parser = (function() {
};
Parser.prototype.cleanup = function(value) {
- var count, trimmedValue, _ref, _ref1, _ref2;
+ var count, i, indent, line, lines, smallestIndent, trimmedValue, _i, _j, _len, _len1, _ref, _ref1, _ref2;
if (value.indexOf("\r") !== -1) {
value = value.split("\r\n").join("\n").split("\r").join("\n");
}
@@ -546,6 +546,22 @@ Parser = (function() {
value = trimmedValue;
value = this.PATTERN_DOCUMENT_MARKER_END.replace(value, '');
}
+ lines = value.split("\n");
+ smallestIndent = -1;
+ for (_i = 0, _len = lines.length; _i < _len; _i++) {
+ line = lines[_i];
+ indent = line.length - Utils.ltrim(line).length;
+ if (smallestIndent === -1 || indent < smallestIndent) {
+ smallestIndent = indent;
+ }
+ }
+ if (smallestIndent > 0) {
+ for (i = _j = 0, _len1 = lines.length; _j < _len1; i = ++_j) {
+ line = lines[i];
+ lines[i] = line.slice(smallestIndent);
+ }
+ value = lines.join("\n");
+ }
return value;
};