Skip to content

Commit

Permalink
Merge pull request #720 from Infocatcher/support-legacy-engines
Browse files Browse the repository at this point in the history
Support for legacy JavaScript versions (e.g. WSH+JScript & Co)
  • Loading branch information
bitwiseman committed Jun 19, 2015
2 parents 1b4be9b + 0aee89a commit 44b213c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
23 changes: 13 additions & 10 deletions js/lib/beautify-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
wrap_attributes = (options.wrap_attributes === undefined) ? 'auto' : options.wrap_attributes;
wrap_attributes_indent_size = (options.wrap_attributes_indent_size === undefined) ? indent_size : parseInt(options.wrap_attributes_indent_size, 10) || indent_size;
end_with_newline = (options.end_with_newline === undefined) ? false : options.end_with_newline;
extra_liners = Array.isArray(options.extra_liners) ?
extra_liners = (typeof options.extra_liners == 'object') && options.extra_liners ?
options.extra_liners.concat() : (typeof options.extra_liners === 'string') ?
options.extra_liners.split(',') : 'head,body,/html'.split(',');
eol = options.eol ? options.eol : '\n';
Expand Down Expand Up @@ -435,23 +435,23 @@

if (tag_complete.indexOf(' ') !== -1) { //if there's whitespace, thats where the tag name ends
tag_index = tag_complete.indexOf(' ');
} else if (tag_complete[0] === '{') {
} else if (tag_complete.charAt(0) === '{') {
tag_index = tag_complete.indexOf('}');
} else { //otherwise go with the tag ending
tag_index = tag_complete.indexOf('>');
}
if (tag_complete[0] === '<' || !indent_handlebars) {
if (tag_complete.charAt(0) === '<' || !indent_handlebars) {
tag_offset = 1;
} else {
tag_offset = tag_complete[2] === '#' ? 3 : 2;
tag_offset = tag_complete.charAt(2) === '#' ? 3 : 2;
}
var tag_check = tag_complete.substring(tag_offset, tag_index).toLowerCase();
if (tag_complete.charAt(tag_complete.length - 2) === '/' ||
this.Utils.in_array(tag_check, this.Utils.single_token)) { //if this tag name is a single tag type (either in the list or has a closing /)
if (!peek) {
this.tag_type = 'SINGLE';
}
} else if (indent_handlebars && tag_complete[0] === '{' && tag_check === 'else') {
} else if (indent_handlebars && tag_complete.charAt(0) === '{' && tag_check === 'else') {
if (!peek) {
this.indent_to_tag('if');
this.tag_type = 'HANDLEBARS_ELSE';
Expand Down Expand Up @@ -531,7 +531,7 @@
comment += input_char;

// only need to check for the delimiter if the last chars match
if (comment[comment.length - 1] === delimiter[delimiter.length - 1] &&
if (comment.charAt(comment.length - 1) === delimiter.charAt(delimiter.length - 1) &&
comment.indexOf(delimiter) !== -1) {
break;
}
Expand Down Expand Up @@ -608,7 +608,7 @@
this.line_char_count++;
space = true;

if (indent_handlebars && input_char === '{' && content.length && content[content.length - 2] === '{') {
if (indent_handlebars && input_char === '{' && content.length && content.charAt(content.length - 2) === '{') {
// Handlebars expressions in strings should also be unformatted.
content += this.get_unformatted('}}');
// These expressions are opaque. Ignore delimiters found in them.
Expand Down Expand Up @@ -747,7 +747,7 @@
}

if (text && text !== '') {
if (text.length > 1 && text[text.length - 1] === '\n') {
if (text.length > 1 && text.charAt(text.length - 1) === '\n') {
// unformatted tags can grab newlines as their last character
this.output.push(text.slice(0, -1));
this.print_newline(false, this.output);
Expand Down Expand Up @@ -869,8 +869,11 @@
if (_beautifier) {

// call the Beautifier if avaliable
var child_options = JSON.parse(JSON.stringify(options));
child_options.eol = '\n';
var Child_options = function() {
this.eol = '\n';
};
Child_options.prototype = options;
var child_options = new Child_options();
text = _beautifier(text.replace(/^\s*/, indentation), child_options);
} else {
// simply indent the string otherwise
Expand Down
2 changes: 1 addition & 1 deletion js/test/beautify-css-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function run_css_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_bea
break_chained_methods: false,
selector_separator: '\n',
end_with_newline: false,
newline_between_rules: true,
newline_between_rules: true
};

function test_css_beautifier(input)
Expand Down
2 changes: 1 addition & 1 deletion test/template/node-css.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function run_css_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_bea
break_chained_methods: false,
selector_separator: '\n',
end_with_newline: false,
newline_between_rules: true,
newline_between_rules: true
};

function test_css_beautifier(input)
Expand Down

0 comments on commit 44b213c

Please sign in to comment.