diff --git a/js/src/core/options.js b/js/src/core/options.js
index 40dd330bd..27e0123c6 100644
--- a/js/src/core/options.js
+++ b/js/src/core/options.js
@@ -46,10 +46,20 @@ function Options(options, merge_child_field) {
this.max_preserve_newlines = 0;
}
- this.indent_with_tabs = this._get_boolean('indent_with_tabs');
+ this.indent_with_tabs = this._get_boolean('indent_with_tabs', this.indent_char === '\t');
if (this.indent_with_tabs) {
this.indent_char = '\t';
- this.indent_size = 1;
+
+ // indent_size behavior changed after 1.8.6
+ // It used to be that indent_size would be
+ // set to 1 for indent_with_tabs. That is no longer needed and
+ // actually doesn't make sense - why not use spaces? Further,
+ // that might produce unexpected behavior - tabs being used
+ // for single-column alignment. So, when indent_with_tabs is true
+ // and indent_size is 1, reset indent_size to 4.
+ if (this.indent_size === 1) {
+ this.indent_size = 4;
+ }
}
// Backwards compat with 1.3.x
diff --git a/js/src/core/output.js b/js/src/core/output.js
index 5e400ffb9..e01ffafeb 100644
--- a/js/src/core/output.js
+++ b/js/src/core/output.js
@@ -1,6 +1,5 @@
/*jshint node:true */
/*
-
The MIT License (MIT)
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
@@ -58,7 +57,7 @@ OutputLine.prototype.has_match = function(pattern) {
OutputLine.prototype.set_indent = function(indent, alignment) {
this.__indent_count = indent || 0;
this.__alignment_count = alignment || 0;
- this.__character_count = this.__parent.baseIndentLength + this.__alignment_count + this.__indent_count * this.__parent.indent_length;
+ this.__character_count = this.__parent.get_indent_size(this.__indent_count, this.__alignment_count);
};
OutputLine.prototype.get_character_count = function() {
@@ -102,7 +101,7 @@ OutputLine.prototype.pop = function() {
OutputLine.prototype.remove_indent = function() {
if (this.__indent_count > 0) {
this.__indent_count -= 1;
- this.__character_count -= this.__parent.indent_length;
+ this.__character_count -= this.__parent.indent_size;
}
};
@@ -116,53 +115,81 @@ OutputLine.prototype.trim = function() {
OutputLine.prototype.toString = function() {
var result = '';
if (!this.is_empty()) {
- if (this.__indent_count >= 0) {
- result = this.__parent.get_indent_string(this.__indent_count);
- }
- if (this.__alignment_count >= 0) {
- result += this.__parent.get_alignment_string(this.__alignment_count);
- }
+ result = this.__parent.get_indent_string(this.__indent_count, this.__alignment_count);
result += this.__items.join('');
}
return result;
};
-function IndentCache(base_string, level_string) {
- this.__cache = [base_string];
- this.__level_string = level_string;
+function IndentStringCache(options, baseIndentString) {
+ this.__cache = [''];
+ this.__indent_size = options.indent_size;
+ this.__indent_string = options.indent_char;
+ if (!options.indent_with_tabs) {
+ this.__indent_string = new Array(options.indent_size + 1).join(options.indent_char);
+ }
+
+ // Set to null to continue support for auto detection of base indent
+ baseIndentString = baseIndentString || '';
+ if (options.indent_level > 0) {
+ baseIndentString = new Array(options.indent_level + 1).join(this.__indent_string);
+ }
+
+ this.__base_string = baseIndentString;
+ this.__base_string_length = baseIndentString.length;
}
-IndentCache.prototype.__ensure_cache = function(level) {
- while (level >= this.__cache.length) {
- this.__cache.push(this.__cache[this.__cache.length - 1] + this.__level_string);
+IndentStringCache.prototype.get_indent_size = function(indent, column) {
+ var result = this.__base_string_length;
+ column = column || 0;
+ if (indent < 0) {
+ result = 0;
}
+ result += indent * this.__indent_size;
+ result += column;
+ return result;
};
-IndentCache.prototype.get_level_string = function(level) {
- this.__ensure_cache(level);
- return this.__cache[level];
+IndentStringCache.prototype.get_indent_string = function(indent_level, column) {
+ var result = this.__base_string;
+ column = column || 0;
+ if (indent_level < 0) {
+ indent_level = 0;
+ result = '';
+ }
+ column += indent_level * this.__indent_size;
+ this.__ensure_cache(column);
+ result += this.__cache[column];
+ return result;
};
-
-function Output(options, baseIndentString) {
- var indent_string = options.indent_char;
- if (options.indent_size > 1) {
- indent_string = new Array(options.indent_size + 1).join(options.indent_char);
+IndentStringCache.prototype.__ensure_cache = function(column) {
+ while (column >= this.__cache.length) {
+ this.__add_column();
}
+};
- // Set to null to continue support for auto detection of base indent level.
- baseIndentString = baseIndentString || '';
- if (options.indent_level > 0) {
- baseIndentString = new Array(options.indent_level + 1).join(indent_string);
+IndentStringCache.prototype.__add_column = function() {
+ var column = this.__cache.length;
+ var indent = 0;
+ var result = '';
+ if (this.__indent_size && column >= this.__indent_size) {
+ indent = Math.floor(column / this.__indent_size);
+ column -= indent * this.__indent_size;
+ result = new Array(indent + 1).join(this.__indent_string);
}
+ if (column) {
+ result += new Array(column + 1).join(' ');
+ }
+
+ this.__cache.push(result);
+};
- this.__indent_cache = new IndentCache(baseIndentString, indent_string);
- this.__alignment_cache = new IndentCache('', ' ');
- this.baseIndentLength = baseIndentString.length;
- this.indent_length = indent_string.length;
+function Output(options, baseIndentString) {
+ this.__indent_cache = new IndentStringCache(options, baseIndentString);
this.raw = false;
this._end_with_newline = options.end_with_newline;
-
+ this.indent_size = options.indent_size;
this.__lines = [];
this.previous_line = null;
this.current_line = null;
@@ -181,12 +208,12 @@ Output.prototype.get_line_number = function() {
return this.__lines.length;
};
-Output.prototype.get_indent_string = function(level) {
- return this.__indent_cache.get_level_string(level);
+Output.prototype.get_indent_string = function(indent, column) {
+ return this.__indent_cache.get_indent_string(indent, column);
};
-Output.prototype.get_alignment_string = function(level) {
- return this.__alignment_cache.get_level_string(level);
+Output.prototype.get_indent_size = function(indent, column) {
+ return this.__indent_cache.get_indent_size(indent, column);
};
Output.prototype.is_empty = function() {
@@ -219,7 +246,6 @@ Output.prototype.get_code = function(eol) {
if (eol !== '\n') {
sweet_code = sweet_code.replace(/[\n]/g, eol);
}
-
return sweet_code;
};
diff --git a/js/src/html/beautifier.js b/js/src/html/beautifier.js
index 2944d8df5..92498d3b1 100644
--- a/js/src/html/beautifier.js
+++ b/js/src/html/beautifier.js
@@ -482,7 +482,6 @@ Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_to
parser_token.alignment_size = raw_token.text.length + 1;
}
-
if (!parser_token.tag_complete && !parser_token.is_unformatted) {
printer.alignment_size = parser_token.alignment_size;
}
diff --git a/js/src/javascript/beautifier.js b/js/src/javascript/beautifier.js
index c42de4cb1..566896eae 100644
--- a/js/src/javascript/beautifier.js
+++ b/js/src/javascript/beautifier.js
@@ -191,6 +191,7 @@ Beautifier.prototype.create_flags = function(flags_base, mode) {
in_case: false, // we're on the exact line with "case 0:"
case_body: false, // the indented case-action block
indentation_level: next_indent_level,
+ alignment: 0,
line_indent_level: flags_base ? flags_base.line_indent_level : next_indent_level,
start_line_index: this._output.get_line_number(),
ternary_depth: 0
@@ -393,7 +394,7 @@ Beautifier.prototype.print_token_line_indentation = function(current_token) {
if (this._options.keep_array_indentation && is_array(this._flags.mode) && current_token.newlines) {
this._output.current_line.push(current_token.whitespace_before);
this._output.space_before_token = false;
- } else if (this._output.set_indent(this._flags.indentation_level)) {
+ } else if (this._output.set_indent(this._flags.indentation_level, this._flags.alignment)) {
this._flags.line_indent_level = this._flags.indentation_level;
}
}
@@ -1343,29 +1344,40 @@ Beautifier.prototype.handle_block_comment = function(current_token, preserve_sta
// block comment starts with a new line
this.print_newline(false, preserve_statement_flags);
- if (lines.length > 1) {
- javadoc = all_lines_start_with(lines.slice(1), '*');
- starless = each_line_matches_indent(lines.slice(1), lastIndent);
- }
// first line always indented
this.print_token(current_token, lines[0]);
- for (j = 1; j < lines.length; j++) {
- this.print_newline(false, true);
+
+
+ if (lines.length > 1) {
+ lines = lines.slice(1);
+ javadoc = all_lines_start_with(lines, '*');
+ starless = each_line_matches_indent(lines, lastIndent);
+
if (javadoc) {
- // javadoc: reformat and re-indent
- this.print_token(current_token, ' ' + ltrim(lines[j]));
- } else if (starless && lines[j].length > lastIndentLength) {
- // starless: re-indent non-empty content, avoiding trim
- this.print_token(current_token, lines[j].substring(lastIndentLength));
- } else {
- // normal comments output raw
- this._output.add_token(lines[j]);
+ this._flags.alignment = 1;
}
+
+ for (j = 0; j < lines.length; j++) {
+ this.print_newline(false, true);
+ if (javadoc) {
+ // javadoc: reformat and re-indent
+ this.print_token(current_token, ltrim(lines[j]));
+ } else if (starless && lines[j]) {
+ // starless: re-indent non-empty content, avoiding trim
+ this.print_token(current_token, lines[j].substring(lastIndentLength));
+ } else {
+ // normal comments output raw
+ this._output.add_token(lines[j]);
+ }
+ }
+
+ this._flags.alignment = 0;
}
- // for comments of more than one line, make sure there's a new line after
+ // for comments on their own line or more than one line, make sure there's a new line after
this.print_newline(false, preserve_statement_flags);
+
};
Beautifier.prototype.handle_comment = function(current_token, preserve_statement_flags) {
diff --git a/js/test/generated/beautify-html-tests.js b/js/test/generated/beautify-html-tests.js
index 32c9df92d..030e0d7a5 100644
--- a/js/test/generated/beautify-html-tests.js
+++ b/js/test/generated/beautify-html-tests.js
@@ -124,8 +124,9 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
success = success && test_fragment(input, expectation);
if (opts.indent_size === 4 && input) {
- wrapped_input = '
\n' + input.replace(/^(.+)$/mg, ' $1') + '\n inline \n
';
- wrapped_expectation = '\n' + expectation.replace(/^(.+)$/mg, ' $1') + '\n inline \n
';
+ var indent_string = opts.indent_with_tabs ? '\t' : ' ';
+ wrapped_input = '\n' + input.replace(/^(.+)$/mg, indent_string + '$1') + '\n' + indent_string + 'inline \n
';
+ wrapped_expectation = '\n' + expectation.replace(/^(.+)$/mg, indent_string + '$1') + '\n' + indent_string + 'inline \n
';
success = success && test_fragment(wrapped_input, wrapped_expectation);
}
return success;
@@ -532,9 +533,9 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
//============================================================
- // Attribute Wrap alignment with spaces - (wrap_attributes = ""force-aligned"", indent_with_tabs = "true")
+ // Attribute Wrap alignment with spaces and tabs - (wrap_attributes = ""force-aligned"", indent_with_tabs = "true")
reset_options();
- set_name('Attribute Wrap alignment with spaces - (wrap_attributes = ""force-aligned"", indent_with_tabs = "true")');
+ set_name('Attribute Wrap alignment with spaces and tabs - (wrap_attributes = ""force-aligned"", indent_with_tabs = "true")');
opts.wrap_attributes = 'force-aligned';
opts.indent_with_tabs = true;
test_fragment(
@@ -542,29 +543,76 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
// -- output --
'\n' +
'\t
\n' +
+ '\t\t b="2">\n' +
'\t\t
test
\n' +
'\t
\n' +
'
');
test_fragment(
' ');
+ '\t name="garage"\n' +
+ '\t id="garage-02"\n' +
+ '\t class="ns-e-togg__radio ns-js-form-binding"\n' +
+ '\t value="02"\n' +
+ '\t {{#ifCond data.antragsart "05"}}\n' +
+ '\t checked="checked"\n' +
+ '\t {{/ifCond}}>');
test_fragment(
'\n' +
'\t \n' +
+ '\t\t name="garage"\n' +
+ '\t\t id="garage-02"\n' +
+ '\t\t class="ns-e-togg__radio ns-js-form-binding"\n' +
+ '\t\t value="02"\n' +
+ '\t\t {{#ifCond data.antragsart "05"}}\n' +
+ '\t\t checked="checked"\n' +
+ '\t\t {{/ifCond}}>\n' +
+ '
');
+ test_fragment(
+ '---\n' +
+ 'layout: mainLayout.html\n' +
+ 'page: default.html\n' +
+ '---\n' +
+ '\n' +
+ '\n' +
+ '\t{{> componentXYZ my.data.key}}\n' +
+ '\t{{> componentABC my.other.data.key}}\n' +
+ '\t
Hello World \n' +
+ '\t
Your paragraph
\n' +
+ '
');
+
+ // Attribute Wrap alignment with spaces and tabs - (wrap_attributes = ""force"", indent_with_tabs = "true")
+ reset_options();
+ set_name('Attribute Wrap alignment with spaces and tabs - (wrap_attributes = ""force"", indent_with_tabs = "true")');
+ opts.wrap_attributes = 'force';
+ opts.indent_with_tabs = true;
+ test_fragment(
+ '',
+ // -- output --
+ '\n' +
+ '\t
\n' +
+ '\t\t
test
\n' +
+ '\t
\n' +
+ '
');
+ test_fragment(
+ ' ');
+ test_fragment(
+ '\n' +
+ '\t \n' +
'
');
test_fragment(
'---\n' +
@@ -651,7 +699,7 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ', '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ');
// Issue 1222 -- P tags are formatting correctly
- test_fragment('Our forms for collecting address-related information follow a standard design. Specific input elements will vary according to the form’s audience and purpose.
');
+ test_fragment('Our forms for collecting address-related information follow a standard design. Specific input elements willl vary according to the form’s audience and purpose.
');
bth('This is some text
', 'This is some text
');
test_fragment(
'This is some text
',
@@ -754,10 +802,10 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
// Issue 1222 -- P tags are formatting correctly
test_fragment(
- 'Our forms for collecting address-related information follow a standard design. Specific input elements will vary according to the form’s audience and purpose.
',
+ 'Our forms for collecting address-related information follow a standard design. Specific input elements willl vary according to the form’s audience and purpose.
',
// -- output --
'Our forms for collecting address-related information follow a standard\n' +
- ' design. Specific input elements will vary according to the form’s audience\n' +
+ ' design. Specific input elements willl vary according to the form’s audience\n' +
' and purpose.
');
bth('This is some text
', 'This is some text
');
test_fragment(
@@ -832,7 +880,7 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ', '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ');
// Issue 1222 -- P tags are formatting correctly
- test_fragment('Our forms for collecting address-related information follow a standard design. Specific input elements will vary according to the form’s audience and purpose.
');
+ test_fragment('Our forms for collecting address-related information follow a standard design. Specific input elements willl vary according to the form’s audience and purpose.
');
bth('This is some text
', 'This is some text
');
test_fragment(
'This is some text
',
@@ -936,10 +984,10 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
// Issue 1222 -- P tags are formatting correctly
test_fragment(
- 'Our forms for collecting address-related information follow a standard design. Specific input elements will vary according to the form’s audience and purpose.
',
+ 'Our forms for collecting address-related information follow a standard design. Specific input elements willl vary according to the form’s audience and purpose.
',
// -- output --
'Our forms for collecting address-related information follow a standard\n' +
- ' design. Specific input elements will vary according to the form’s audience\n' +
+ ' design. Specific input elements willl vary according to the form’s audience\n' +
' and purpose.
');
bth('This is some text
', 'This is some text
');
test_fragment('This is some text
');
@@ -1027,10 +1075,10 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
// Issue 1222 -- P tags are formatting correctly
test_fragment(
- 'Our forms for collecting address-related information follow a standard design. Specific input elements will vary according to the form’s audience and purpose.
',
+ 'Our forms for collecting address-related information follow a standard design. Specific input elements willl vary according to the form’s audience and purpose.
',
// -- output --
'Our forms for collecting address-related information follow a standard\n' +
- ' design. Specific input elements will vary according to the form’s audience\n' +
+ ' design. Specific input elements willl vary according to the form’s audience\n' +
' and purpose.
');
bth('This is some text
', 'This is some text
');
test_fragment('This is some text
');
@@ -1088,7 +1136,7 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ', '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ');
// Issue 1222 -- P tags are formatting correctly
- test_fragment('Our forms for collecting address-related information follow a standard design. Specific input elements will vary according to the form’s audience and purpose.
');
+ test_fragment('Our forms for collecting address-related information follow a standard design. Specific input elements willl vary according to the form’s audience and purpose.
');
bth('This is some text
', 'This is some text
');
test_fragment('This is some text
');
test_fragment('This is some text
');
@@ -1130,7 +1178,7 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ', '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ');
// Issue 1222 -- P tags are formatting correctly
- test_fragment('Our forms for collecting address-related information follow a standard design. Specific input elements will vary according to the form’s audience and purpose.
');
+ test_fragment('Our forms for collecting address-related information follow a standard design. Specific input elements willl vary according to the form’s audience and purpose.
');
bth('This is some text
', 'This is some text
');
test_fragment(
'This is some text
',
@@ -1233,10 +1281,10 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
// Issue 1222 -- P tags are formatting correctly
test_fragment(
- 'Our forms for collecting address-related information follow a standard design. Specific input elements will vary according to the form’s audience and purpose.
',
+ 'Our forms for collecting address-related information follow a standard design. Specific input elements willl vary according to the form’s audience and purpose.
',
// -- output --
'Our forms for collecting address-related information follow a standard\n' +
- ' design. Specific input elements will vary according to the form’s audience\n' +
+ ' design. Specific input elements willl vary according to the form’s audience\n' +
' and purpose.
');
bth('This is some text
', 'This is some text
');
test_fragment(
@@ -1340,10 +1388,10 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
// Issue 1222 -- P tags are formatting correctly
test_fragment(
- 'Our forms for collecting address-related information follow a standard design. Specific input elements will vary according to the form’s audience and purpose.
',
+ 'Our forms for collecting address-related information follow a standard design. Specific input elements willl vary according to the form’s audience and purpose.
',
// -- output --
'Our forms for collecting address-related information follow a standard\n' +
- ' design. Specific input elements will vary according to the form’s audience\n' +
+ ' design. Specific input elements willl vary according to the form’s audience\n' +
' and purpose.
');
bth('This is some text
', 'This is some text
');
test_fragment('This is some text
');
@@ -1400,7 +1448,7 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ', '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ');
// Issue 1222 -- P tags are formatting correctly
- test_fragment('Our forms for collecting address-related information follow a standard design. Specific input elements will vary according to the form’s audience and purpose.
');
+ test_fragment('Our forms for collecting address-related information follow a standard design. Specific input elements willl vary according to the form’s audience and purpose.
');
bth('This is some text
', 'This is some text
');
test_fragment('This is some text
');
test_fragment('This is some text
');
@@ -1443,7 +1491,7 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ', '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ');
// Issue 1222 -- P tags are formatting correctly
- test_fragment('Our forms for collecting address-related information follow a standard design. Specific input elements will vary according to the form’s audience and purpose.
');
+ test_fragment('Our forms for collecting address-related information follow a standard design. Specific input elements willl vary according to the form’s audience and purpose.
');
bth('This is some text
', 'This is some text
');
test_fragment(
'This is some text
',
@@ -1517,7 +1565,7 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ', '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ');
// Issue 1222 -- P tags are formatting correctly
- test_fragment('Our forms for collecting address-related information follow a standard design. Specific input elements will vary according to the form’s audience and purpose.
');
+ test_fragment('Our forms for collecting address-related information follow a standard design. Specific input elements willl vary according to the form’s audience and purpose.
');
bth('This is some text
', 'This is some text
');
test_fragment(
'This is some text
',
@@ -1635,10 +1683,10 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
// Issue 1222 -- P tags are formatting correctly
test_fragment(
- 'Our forms for collecting address-related information follow a standard design. Specific input elements will vary according to the form’s audience and purpose.
',
+ 'Our forms for collecting address-related information follow a standard design. Specific input elements willl vary according to the form’s audience and purpose.
',
// -- output --
'Our forms for collecting address-related information follow a standard\n' +
- ' design. Specific input elements will vary according to the form’s audience\n' +
+ ' design. Specific input elements willl vary according to the form’s audience\n' +
' and purpose.
');
bth('This is some text
', 'This is some text
');
test_fragment(
@@ -1727,7 +1775,7 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ', '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ');
// Issue 1222 -- P tags are formatting correctly
- test_fragment('Our forms for collecting address-related information follow a standard design. Specific input elements will vary according to the form’s audience and purpose.
');
+ test_fragment('Our forms for collecting address-related information follow a standard design. Specific input elements willl vary according to the form’s audience and purpose.
');
bth('This is some text
', 'This is some text
');
test_fragment(
'This is some text
',
@@ -1792,6 +1840,306 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
' type="text/css"\n' +
'>');
+ // Attribute Wrap - (wrap_attributes = ""force-expand-multiline"", wrap_attributes_indent_size = "4", indent_with_tabs = "true")
+ reset_options();
+ set_name('Attribute Wrap - (wrap_attributes = ""force-expand-multiline"", wrap_attributes_indent_size = "4", indent_with_tabs = "true")');
+ opts.wrap_attributes = 'force-expand-multiline';
+ opts.wrap_attributes_indent_size = 4;
+ opts.indent_with_tabs = true;
+ bth('This is some text
', 'This is some text
');
+ test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 ');
+ test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 ', '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 ');
+ test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014\t0015 0016 0017 0018 0019 0020 ', '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 ');
+
+ // issue #869
+ test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 ');
+
+ // TODO: This is wrong - goes over line length but respects
+ test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0015 0016 0017 0018 0019 0020 ', '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0015 0016 0017 0018 0019 0020 ');
+
+ // issue #1496 - respect unicode non-breaking space
+ test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic 0013 0014' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ', '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic 0013 0014' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ');
+
+ // TODO: This is wrong - goes over line length but respects unicode nbsp
+ test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ', '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ');
+
+ // Issue 1222 -- P tags are formatting correctly
+ test_fragment('Our forms for collecting address-related information follow a standard design. Specific input elements willl vary according to the form’s audience and purpose.
');
+ bth('This is some text
', 'This is some text
');
+ test_fragment(
+ 'This is some text
',
+ // -- output --
+ 'This is some text
');
+ test_fragment(
+ 'This is some text
',
+ // -- output --
+ 'This is some text
');
+ test_fragment(
+ ' ',
+ // -- output --
+ ' ');
+ test_fragment(
+ ' ',
+ // -- output --
+ '\n' +
+ ' ');
+
+ // Issue #1094 - Beautify correctly without quotes and with extra spaces
+ test_fragment(
+ 'This is some text
',
+ // -- output --
+ 'This is some text
');
+ test_fragment(
+ ' ',
+ // -- output --
+ '\n' +
+ ' ');
+ test_fragment(
+ ' ',
+ // -- output --
+ ' ');
+
+ // Attribute Wrap - (wrap_attributes = ""force-expand-multiline"", wrap_attributes_indent_size = "7", indent_with_tabs = "true")
+ reset_options();
+ set_name('Attribute Wrap - (wrap_attributes = ""force-expand-multiline"", wrap_attributes_indent_size = "7", indent_with_tabs = "true")');
+ opts.wrap_attributes = 'force-expand-multiline';
+ opts.wrap_attributes_indent_size = 7;
+ opts.indent_with_tabs = true;
+ bth('This is some text
', 'This is some text
');
+ test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 ');
+ test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 ', '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 ');
+ test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014\t0015 0016 0017 0018 0019 0020 ', '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 ');
+
+ // issue #869
+ test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 ');
+
+ // TODO: This is wrong - goes over line length but respects
+ test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0015 0016 0017 0018 0019 0020 ', '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0015 0016 0017 0018 0019 0020 ');
+
+ // issue #1496 - respect unicode non-breaking space
+ test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic 0013 0014' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ', '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic 0013 0014' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ');
+
+ // TODO: This is wrong - goes over line length but respects unicode nbsp
+ test_fragment('0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ', '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ');
+
+ // Issue 1222 -- P tags are formatting correctly
+ test_fragment('Our forms for collecting address-related information follow a standard design. Specific input elements willl vary according to the form’s audience and purpose.
');
+ bth('This is some text
', 'This is some text
');
+ test_fragment(
+ 'This is some text
',
+ // -- output --
+ 'This is some text
');
+ test_fragment(
+ 'This is some text
',
+ // -- output --
+ 'This is some text
');
+ test_fragment(
+ ' ',
+ // -- output --
+ ' ');
+ test_fragment(
+ ' ',
+ // -- output --
+ '\n' +
+ ' ');
+
+ // Issue #1094 - Beautify correctly without quotes and with extra spaces
+ test_fragment(
+ 'This is some text
',
+ // -- output --
+ 'This is some text
');
+ test_fragment(
+ ' ',
+ // -- output --
+ '\n' +
+ ' ');
+ test_fragment(
+ ' ',
+ // -- output --
+ ' ');
+
+ // Attribute Wrap - (wrap_attributes = ""force-expand-multiline"", wrap_line_length = "80", indent_with_tabs = "true")
+ reset_options();
+ set_name('Attribute Wrap - (wrap_attributes = ""force-expand-multiline"", wrap_line_length = "80", indent_with_tabs = "true")');
+ opts.wrap_attributes = 'force-expand-multiline';
+ opts.wrap_line_length = 80;
+ opts.indent_with_tabs = true;
+ bth('This is some text
', 'This is some text
');
+ test_fragment(
+ '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 ',
+ // -- output --
+ '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014\n' +
+ '\t0015 0016 0017 0018 0019 0020 ');
+ test_fragment(
+ '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 ',
+ // -- output --
+ '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014\n' +
+ '\t0015 0016 0017 0018 0019 0020 ');
+ test_fragment(
+ '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014\t0015 0016 0017 0018 0019 0020 ',
+ // -- output --
+ '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014\n' +
+ '\t0015 0016 0017 0018 0019 0020 ');
+
+ // issue #869
+ test_fragment(
+ '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 ',
+ // -- output --
+ '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013\n' +
+ '\t0014 0015 0016 0017 0018 0019 0020 ');
+
+ // TODO: This is wrong - goes over line length but respects
+ test_fragment(
+ '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0015 0016 0017 0018 0019 0020 ',
+ // -- output --
+ '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0015\n' +
+ '\t0016 0017 0018 0019 0020 ');
+
+ // issue #1496 - respect unicode non-breaking space
+ test_fragment(
+ '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic 0013 0014' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ',
+ // -- output --
+ '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic 0013\n' +
+ '\t0014' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ');
+
+ // TODO: This is wrong - goes over line length but respects unicode nbsp
+ test_fragment(
+ '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015 0016 0017 0018 0019 0020 ',
+ // -- output --
+ '0 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 unic ' + unicode_char(160) + ' ' + unicode_char(160) + '0015\n' +
+ '\t0016 0017 0018 0019 0020 ');
+
+ // Issue 1222 -- P tags are formatting correctly
+ test_fragment(
+ 'Our forms for collecting address-related information follow a standard design. Specific input elements willl vary according to the form’s audience and purpose.
',
+ // -- output --
+ 'Our forms for collecting address-related information follow a standard\n' +
+ '\tdesign. Specific input elements willl vary according to the form’s audience\n' +
+ '\tand purpose.
');
+ bth('This is some text
', 'This is some text
');
+ test_fragment(
+ 'This is some text
',
+ // -- output --
+ 'This is some text
');
+ test_fragment(
+ 'This is some text
',
+ // -- output --
+ 'This is some text
');
+ test_fragment(
+ ' ',
+ // -- output --
+ ' ');
+ test_fragment(
+ ' ',
+ // -- output --
+ '\n' +
+ ' ');
+
+ // Issue #1094 - Beautify correctly without quotes and with extra spaces
+ test_fragment(
+ 'This is some text
',
+ // -- output --
+ 'This is some text
');
+ test_fragment(
+ ' ',
+ // -- output --
+ '\n' +
+ ' ');
+ test_fragment(
+ ' ',
+ // -- output --
+ ' ');
+
//============================================================
// Issue #1335 -- Bug with force-expand-multiline formatting
diff --git a/python/jsbeautifier/core/options.py b/python/jsbeautifier/core/options.py
index eb813a58d..78bd41ae0 100644
--- a/python/jsbeautifier/core/options.py
+++ b/python/jsbeautifier/core/options.py
@@ -45,16 +45,26 @@ def __init__(self, options=None, merge_child_field=None):
self.indent_level = self._get_number('indent_level')
self.preserve_newlines = self._get_boolean('preserve_newlines', True)
- # TODO: fix difference in js and python
self.max_preserve_newlines = self._get_number(
- 'max_preserve_newlines', 10)
+ 'max_preserve_newlines', 32786)
+
if not self.preserve_newlines:
self.max_preserve_newlines = 0
- self.indent_with_tabs = self._get_boolean('indent_with_tabs')
+ self.indent_with_tabs = self._get_boolean(
+ 'indent_with_tabs', self.indent_char == '\t')
if self.indent_with_tabs:
self.indent_char = '\t'
- self.indent_size = 1
+
+ # indent_size behavior changed after 1.8.6
+ # It used to be that indent_size would be
+ # set to 1 for indent_with_tabs. That is no longer needed and
+ # actually doesn't make sense - why not use spaces? Further,
+ # that might produce unexpected behavior - tabs being used
+ # for single-column alignment. So, when indent_with_tabs is true
+ # and indent_size is 1, reset indent_size to 4.
+ if self.indent_size == 1:
+ self.indent_size = 4
# Backwards compat with 1.3.x
self.wrap_line_length = self._get_number(
diff --git a/python/jsbeautifier/core/output.py b/python/jsbeautifier/core/output.py
index bce347e67..3ef049f51 100644
--- a/python/jsbeautifier/core/output.py
+++ b/python/jsbeautifier/core/output.py
@@ -23,6 +23,7 @@
# SOFTWARE.
import re
+import math
# Using object instead of string to allow for later expansion of info
# about each line
@@ -42,18 +43,17 @@ def __init__(self, parent):
def item(self, index):
return self.__items[index]
- def get_character_count(self):
- return self.__character_count
-
def is_empty(self):
return len(self.__items) == 0
def set_indent(self, indent=0, alignment=0):
self.__indent_count = indent
self.__alignment_count = alignment
- self.__character_count = self.__parent.baseIndentLength + \
- self.__alignment_count + \
- self.__indent_count * self.__parent.indent_length
+ self.__character_count = self.__parent.get_indent_size(
+ self.__indent_count, self.__alignment_count)
+
+ def get_character_count(self):
+ return self.__character_count
def last(self):
if not self.is_empty():
@@ -75,7 +75,7 @@ def pop(self):
def remove_indent(self):
if self.__indent_count > 0:
self.__indent_count -= 1
- self.__character_count -= self.__parent.indent_length
+ self.__character_count -= self.__parent.indent_size
def trim(self):
while self.last() == ' ':
@@ -85,52 +85,75 @@ def trim(self):
def toString(self):
result = ''
if not self.is_empty():
- if self.__indent_count >= 0:
- result = self.__parent.get_indent_string(self.__indent_count)
- if self.__alignment_count >= 0:
- result += self.__parent.get_alignment_string(
- self.__alignment_count)
+ result = self.__parent.get_indent_string(
+ self.__indent_count, self.__alignment_count)
result += ''.join(self.__items)
return result
-class IndentCache:
- def __init__(self, base_string, level_string):
- self.__cache = [base_string]
- self.__level_string = level_string
+class IndentStringCache:
+ def __init__(self, options, base_string):
+ self.__cache = ['']
+ self.__indent_size = options.indent_size
+ self.__indent_string = options.indent_char
+ if not options.indent_with_tabs:
+ self.__indent_string = options.indent_char * options.indent_size
- def __ensure_cache(self, level):
- while level >= len(self.__cache):
- self.__cache.append(
- self.__cache[-1] + self.__level_string)
+ # Set to null to continue support of auto detection of base indent
+ base_string = base_string or ''
+ if options.indent_level > 0:
+ base_string = options.indent_level * self.__indent_string
- def get_level_string(self, level):
- self.__ensure_cache(level)
- return self.__cache[level]
+ self.__base_string = base_string
+ self.__base_string_length = len(base_string)
+ def get_indent_size(self, indent, column=0):
+ result = self.__base_string_length
+ if indent < 0:
+ result = 0
+ result += indent * self.__indent_size
+ result += column
+ return result
-class Output:
- def __init__(self, options, baseIndentString=''):
+ def get_indent_string(self, indent_level, column=0):
+ result = self.__base_string
+ if indent_level < 0:
+ indent_level = 0
+ result = ''
+ column += indent_level * self.__indent_size
+ self.__ensure_cache(column)
+ result += self.__cache[column]
+ return result
- indent_string = options.indent_char
- if options.indent_size > 0:
- indent_string = options.indent_char * options.indent_size
+ def __ensure_cache(self, column):
+ while column >= len(self.__cache):
+ self.__add_column()
+
+ def __add_column(self):
+ column = len(self.__cache)
+ indent = 0
+ result = ''
+ if self.__indent_size and column >= self.__indent_size:
+ indent = int(math.floor(column / self.__indent_size))
+ column -= indent * self.__indent_size
+ result = indent * self.__indent_string
+ if column:
+ result += column * ' '
+ self.__cache.append(result)
- # Set to null to continue support for auto detection of base levelself.
- if options.indent_level > 0:
- baseIndentString = options.indent_level * indent_string
- self.__indent_cache = IndentCache(baseIndentString, indent_string)
- self.__alignment_cache = IndentCache('', ' ')
- self.baseIndentLength = len(baseIndentString)
- self.indent_length = len(indent_string)
+class Output:
+ def __init__(self, options, baseIndentString=''):
+
+ self.__indent_cache = IndentStringCache(options, baseIndentString)
self.raw = False
self._end_with_newline = options.end_with_newline
+ self.indent_size = options.indent_size
self.__lines = []
self.previous_line = None
self.current_line = None
self.space_before_token = False
-
+ # initialize
self.__add_outputline()
def __add_outputline(self):
@@ -141,11 +164,11 @@ def __add_outputline(self):
def get_line_number(self):
return len(self.__lines)
- def get_indent_string(self, level):
- return self.__indent_cache.get_level_string(level)
+ def get_indent_string(self, indent, column=0):
+ return self.__indent_cache.get_indent_string(indent, column)
- def get_alignment_string(self, level):
- return self.__alignment_cache.get_level_string(level)
+ def get_indent_size(self, indent, column=0):
+ return self.__indent_cache.get_indent_size(indent, column)
def is_empty(self):
return self.previous_line is None and self.current_line.is_empty()
diff --git a/python/jsbeautifier/javascript/beautifier.py b/python/jsbeautifier/javascript/beautifier.py
index a4991dea1..a2aa0a861 100644
--- a/python/jsbeautifier/javascript/beautifier.py
+++ b/python/jsbeautifier/javascript/beautifier.py
@@ -55,6 +55,7 @@ def __init__(self, mode):
self.in_case_statement = False
self.case_body = False
self.indentation_level = 0
+ self.alignment = 0
self.line_indent_level = 0
self.start_line_index = 0
self.ternary_depth = 0
@@ -324,7 +325,8 @@ def print_token_line_indentation(self, current_token):
self._flags.mode) and current_token.newlines:
line.push(current_token.whitespace_before)
self._output.space_before_token = False
- elif self._output.set_indent(self._flags.indentation_level):
+ elif self._output.set_indent(self._flags.indentation_level,
+ self._flags.alignment):
self._flags.line_indent_level = self._flags.indentation_level
def print_token(self, current_token, s=None):
@@ -1236,26 +1238,36 @@ def handle_block_comment(self, current_token, preserve_statement_flags):
# block comment starts with a new line
self.print_newline(preserve_statement_flags=preserve_statement_flags)
+
+ # first line always indented
+ self.print_token(current_token, lines[0])
+
if len(lines) > 1:
- javadoc = not any(l for l in lines[1:] if (
+ lines = lines[1:]
+ javadoc = not any(l for l in lines if (
l.strip() == '' or (l.lstrip())[0] != '*'))
starless = all(l.startswith(last_indent)
- or l.strip() == '' for l in lines[1:])
+ or l.strip() == '' for l in lines)
- # first line always indented
- self.print_token(current_token, lines[0])
- for line in lines[1:]:
- self.print_newline(preserve_statement_flags=True)
if javadoc:
- # javadoc: reformat and re-indent
- self.print_token(current_token, ' ' + line.lstrip())
- elif starless and len(line) > last_indent_length:
- # starless: re-indent non-empty content, avoiding trim
- self.print_token(current_token, line[last_indent_length:])
- else:
- # normal comments output raw
- self._output.add_token(line)
+ self._flags.alignment = 1
+
+ for line in lines:
+ self.print_newline(preserve_statement_flags=True)
+ if javadoc:
+ # javadoc: reformat and re-indent
+ self.print_token(current_token, line.lstrip())
+ elif starless and len(line) > last_indent_length:
+ # starless: re-indent non-empty content, avoiding trim
+ self.print_token(current_token, line[last_indent_length:])
+ else:
+ # normal comments output raw
+ self._output.add_token(line)
+
+ self._flags.alignment = 0
+ # for comments on their own line or more than one line,
+ # make sure there's a new line after
self.print_newline(preserve_statement_flags=preserve_statement_flags)
def handle_comment(self, current_token, preserve_statement_flags):
diff --git a/python/jsbeautifier/tests/generated/tests.py b/python/jsbeautifier/tests/generated/tests.py
index 316b20158..dfd15e071 100644
--- a/python/jsbeautifier/tests/generated/tests.py
+++ b/python/jsbeautifier/tests/generated/tests.py
@@ -7296,9 +7296,8 @@ def test_beautifier_unconverted(self):
bt('if(a &&\nb\n||\nc\n||d\n&&\ne) e = f', 'if (a &&\n b ||\n c ||\n d &&\n e) e = f')
bt('if(a &&\n(b\n||\nc\n||d)\n&&\ne) e = f', 'if (a &&\n (b ||\n c ||\n d) &&\n e) e = f')
test_fragment('\n\n"x"', '"x"')
- # this beavior differs between js and python, defaults to unlimited in js, 10 in python
bt('a = 1;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nb = 2;',
- 'a = 1;\n\n\n\n\n\n\n\n\n\nb = 2;')
+ 'a = 1;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nb = 2;')
self.options.max_preserve_newlines = 8
bt('a = 1;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nb = 2;',
'a = 1;\n\n\n\n\n\n\n\nb = 2;')
diff --git a/test/data/html/node.mustache b/test/data/html/node.mustache
index f620edbc2..7c13e4903 100644
--- a/test/data/html/node.mustache
+++ b/test/data/html/node.mustache
@@ -115,8 +115,9 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
success = success && test_fragment(input, expectation);
if (opts.indent_size === 4 && input) {
- wrapped_input = '\n' + input.replace(/^(.+)$/mg, ' $1') + '\n inline \n
';
- wrapped_expectation = '\n' + expectation.replace(/^(.+)$/mg, ' $1') + '\n inline \n
';
+ var indent_string = opts.indent_with_tabs ? '\t' : ' ';
+ wrapped_input = '\n' + input.replace(/^(.+)$/mg, indent_string + '$1') + '\n' + indent_string + 'inline \n
';
+ wrapped_expectation = '\n' + expectation.replace(/^(.+)$/mg, indent_string + '$1') + '\n' + indent_string + 'inline \n
';
success = success && test_fragment(wrapped_input, wrapped_expectation);
}
return success;
diff --git a/test/data/html/tests.js b/test/data/html/tests.js
index f7c01fdcf..f0e6d90c1 100644
--- a/test/data/html/tests.js
+++ b/test/data/html/tests.js
@@ -357,31 +357,40 @@ exports.test_data = {
]
}, {
- name: "Attribute Wrap alignment with spaces",
+ name: "Attribute Wrap alignment with spaces and tabs",
description: "Ensure attributes are internally aligned with spaces when the indent_character is set to tab",
template: "^^^ $$$",
matrix: [{
options: [
{ name: "wrap_attributes", value: "'force-aligned'" },
{ name: "indent_with_tabs", value: "true" }
- ]
+ ],
+ indent_attr: '\t ',
+ indent_div_attr: '\t '
+ }, {
+ options: [
+ { name: "wrap_attributes", value: "'force'" },
+ { name: "indent_with_tabs", value: "true" }
+ ],
+ indent_attr: '\t',
+ indent_div_attr: '\t'
}],
tests: [{
fragment: true,
input: '',
- output: ''
+ output: ''
},
{
fragment: true,
unchanged: [
' '
+ '^^^indent_attr$$$name="garage"',
+ '^^^indent_attr$$$id="garage-02"',
+ '^^^indent_attr$$$class="ns-e-togg__radio ns-js-form-binding"',
+ '^^^indent_attr$$$value="02"',
+ '^^^indent_attr$$${{#ifCond data.antragsart "05"}}',
+ '^^^indent_attr$$$checked="checked"',
+ '^^^indent_attr$$${{/ifCond}}>'
]
},
{
@@ -389,13 +398,13 @@ exports.test_data = {
unchanged: [
'',
'\t ',
+ '\t^^^indent_attr$$$name="garage"',
+ '\t^^^indent_attr$$$id="garage-02"',
+ '\t^^^indent_attr$$$class="ns-e-togg__radio ns-js-form-binding"',
+ '\t^^^indent_attr$$$value="02"',
+ '\t^^^indent_attr$$${{#ifCond data.antragsart "05"}}',
+ '\t^^^indent_attr$$$checked="checked"',
+ '\t^^^indent_attr$$${{/ifCond}}>',
'
'
]
},
@@ -630,6 +639,45 @@ exports.test_data = {
indent_content80_selfclosing: ' ',
indent_content80: ' ',
indent_over80: '\n '
+ }, {
+ options: [
+ { name: "wrap_attributes", value: "'force-expand-multiline'" },
+ { name: "wrap_attributes_indent_size", value: "4" },
+ { name: "indent_with_tabs", value: 'true' }
+ ],
+ indent_attr: '\n\t',
+ indent_attr_first: '\n\t',
+ indent_end: '\n',
+ indent_end_selfclosing: '\n',
+ indent_content80_selfclosing: ' ',
+ indent_content80: ' ',
+ indent_over80: '\n\t'
+ }, {
+ options: [
+ { name: "wrap_attributes", value: "'force-expand-multiline'" },
+ { name: "wrap_attributes_indent_size", value: "7" },
+ { name: "indent_with_tabs", value: 'true' }
+ ],
+ indent_attr: '\n\t ',
+ indent_attr_first: '\n\t ',
+ indent_end: '\n',
+ indent_end_selfclosing: '\n',
+ indent_content80_selfclosing: ' ',
+ indent_content80: ' ',
+ indent_over80: '\n\t '
+ }, {
+ options: [
+ { name: "wrap_attributes", value: "'force-expand-multiline'" },
+ { name: "wrap_line_length", value: "80" },
+ { name: "indent_with_tabs", value: 'true' }
+ ],
+ indent_attr: '\n\t',
+ indent_attr_first: '\n\t',
+ indent_end: '\n',
+ indent_end_selfclosing: '\n',
+ indent_content80_selfclosing: ' ',
+ indent_content80: '\n\t',
+ indent_over80: '\n\t'
}],
tests: [{
input: 'This is some text
',
@@ -669,8 +717,8 @@ exports.test_data = {
}, {
fragment: true,
comment: 'Issue 1222 -- P tags are formatting correctly',
- input: 'Our forms for collecting address-related information follow a standard design. Specific input elements will vary according to the form’s audience and purpose.
',
- output: 'Our forms for collecting address-related information follow a standard{{indent_content80}}design. Specific input elements will vary according to the form’s audience{{indent_content80}}and purpose.
'
+ input: 'Our forms for collecting address-related information follow a standard design. Specific input elements willl vary according to the form’s audience and purpose.
',
+ output: 'Our forms for collecting address-related information follow a standard{{indent_content80}}design. Specific input elements willl vary according to the form’s audience{{indent_content80}}and purpose.
'
}, {
input: 'This is some text
',
output: 'This is some text
'
diff --git a/test/data/javascript/python.mustache b/test/data/javascript/python.mustache
index 7fda2227d..b0dc72bad 100644
--- a/test/data/javascript/python.mustache
+++ b/test/data/javascript/python.mustache
@@ -1269,9 +1269,8 @@ class TestJSBeautifier(unittest.TestCase):
bt('if(a &&\nb\n||\nc\n||d\n&&\ne) e = f', 'if (a &&\n b ||\n c ||\n d &&\n e) e = f')
bt('if(a &&\n(b\n||\nc\n||d)\n&&\ne) e = f', 'if (a &&\n (b ||\n c ||\n d) &&\n e) e = f')
test_fragment('\n\n"x"', '"x"')
- # this beavior differs between js and python, defaults to unlimited in js, 10 in python
bt('a = 1;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nb = 2;',
- 'a = 1;\n\n\n\n\n\n\n\n\n\nb = 2;')
+ 'a = 1;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nb = 2;')
self.options.max_preserve_newlines = 8
bt('a = 1;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nb = 2;',
'a = 1;\n\n\n\n\n\n\n\nb = 2;')