Skip to content

Commit

Permalink
Fix #1102 and fix #1103 attribute wrapping issues
Browse files Browse the repository at this point in the history
  • Loading branch information
HookyQR committed Feb 10, 2017
1 parent 39c777e commit b149d02
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
11 changes: 7 additions & 4 deletions js/lib/beautify-html.js
Expand Up @@ -490,7 +490,8 @@
}

for (var count = 0; count < alignment_size; count++) {
content.push(indent_character);
// only ever further indent with spaces since we're trying to align characters
content.push(' ');
}
}
if (first_attr) {
Expand Down Expand Up @@ -557,10 +558,12 @@
var tag_index;
var tag_offset;

if (tag_complete.indexOf('\n') !== -1) { //if there's a line break, thats where the tag name ends
tag_index = tag_complete.indexOf('\n');
} else if (tag_complete.indexOf(' ') !== -1) { //if there's whitespace, thats where the tag name ends
// must check for space first otherwise the tag could have the first attribute included, and
// then not un-indent correctly
if (tag_complete.indexOf(' ') !== -1) { //if there's whitespace, thats where the tag name ends
tag_index = tag_complete.indexOf(' ');
} else if (tag_complete.indexOf('\n') !== -1) { //if there's a line break, thats where the tag name ends
tag_index = tag_complete.indexOf('\n');
} else if (tag_complete.charAt(0) === '{') {
tag_index = tag_complete.indexOf('}');
} else { //otherwise go with the tag ending
Expand Down
16 changes: 16 additions & 0 deletions js/test/generated/beautify-html-tests.js
Expand Up @@ -286,6 +286,22 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
'</style>');


//============================================================
// Attribute Wrap alignment with spaces - ()
reset_options();
opts.wrap_attributes = 'force-aligned';
opts.indent_with_tabs = true;
test_fragment('<div><div a="1" b="2"><div>test</div></div></div>', '<div>\n\t<div a="1"\n\t b="2">\n\t\t<div>test</div>\n\t</div>\n</div>');


//============================================================
// Attribute Wrap de-indent - ()
reset_options();
opts.wrap_attributes = 'force-aligned';
opts.indent_with_tabs = false;
bth('<div a="1" b="2"><div>test</div></div>', '<div a="1"\n b="2">\n <div>test</div>\n</div>');


//============================================================
// Attribute Wrap - (indent_attr = "\n ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")
reset_options();
Expand Down
28 changes: 28 additions & 0 deletions test/data/html/tests.js
Expand Up @@ -280,6 +280,34 @@ exports.test_data = {
},

],
}, {
name: "Attribute Wrap alignment with spaces",
description: "Ensure attributes are internally aligned with spaces when the indent_character is set to tab",
matrix: [{
options: [
{ name: "wrap_attributes", value: "'force-aligned'" },
{ name: "indent_with_tabs", value: "true" }
]
}],
tests: [{
fragment: true,
input: '<div><div a="1" b="2"><div>test</div></div></div>',
output: '<div>\n\t<div a="1"\n\t b="2">\n\t\t<div>test</div>\n\t</div>\n</div>'
}]
}, {
name: "Attribute Wrap de-indent",
description: "Tags de-indent when attributes are wrapped",
matrix: [{
options: [
{ name: "wrap_attributes", value: "'force-aligned'" },
{ name: "indent_with_tabs", value: "false" }
]
}],
tests: [{
fragement: true,
input: '<div a="1" b="2"><div>test</div></div>',
output: '<div a="1"\n b="2">\n <div>test</div>\n</div>'
}]
}, {
name: "Attribute Wrap",
description: "Wraps attributes inside of html tags",
Expand Down

0 comments on commit b149d02

Please sign in to comment.