Added option "force-expand-multiline" for "wrap_attributes" (#1070)

* introduce "wrap_attributes": "force-all"

result:
<tag
  attribute="hugo"
  other-attribute="sepp"
/>

* introduce "wrap_attributes": "force-all"

fix bug with indendation of previous wrap options

* introduce "wrap_attributes": "force-all"

cleanup

* introduce "wrap_attributes": "force-all"

add unit tests

* rename "wrap_attributes": "force-all" to "wrap_attributes": "force-expand-multiline"
This commit is contained in:
Tobias Zucali 2016-12-16 16:54:11 +01:00 committed by Liam Newman
parent 797e3126ac
commit a32d9d8432
4 changed files with 174 additions and 28 deletions

View File

@ -216,7 +216,7 @@ HTML Beautifier Options:
-b, --brace-style [collapse-preserve-inline|collapse|expand|end-expand|none] ["collapse"]
-S, --indent-scripts [keep|separate|normal] ["normal"]
-w, --wrap-line-length Maximum characters per line (0 disables) [250]
-A, --wrap-attributes Wrap attributes to new lines [auto|force|force-aligned] ["auto"]
-A, --wrap-attributes Wrap attributes to new lines [auto|force|force-aligned|force-expand-multiline] ["auto"]
-i, --wrap-attributes-indent-size Indent wrapped attributes to after N characters [indent-size] (ignored if wrap-attributes is "force-aligned")
-U, --unformatted List of tags (defaults to inline) that should not be reformatted
-E, --extra_liners List of tags (defaults to [head,body,/html] that should have an extra newline before them.

View File

@ -102,6 +102,8 @@
wrap_attributes,
wrap_attributes_indent_size,
is_wrap_attributes_force,
is_wrap_attributes_force_expand_multiline,
is_wrap_attributes_force_aligned,
end_with_newline,
extra_liners,
eol;
@ -141,6 +143,8 @@
wrap_attributes = (options.wrap_attributes === undefined) ? 'auto' : options.wrap_attributes;
wrap_attributes_indent_size = (isNaN(parseInt(options.wrap_attributes_indent_size, 10))) ? indent_size : parseInt(options.wrap_attributes_indent_size, 10);
is_wrap_attributes_force = wrap_attributes.substr(0, 'force'.length) === 'force';
is_wrap_attributes_force_expand_multiline = (wrap_attributes === 'force-expand-multiline');
is_wrap_attributes_force_aligned = (wrap_attributes === 'force-aligned');
end_with_newline = (options.end_with_newline === undefined) ? false : options.end_with_newline;
extra_liners = (typeof options.extra_liners === 'object') && options.extra_liners ?
options.extra_liners.concat() : (typeof options.extra_liners === 'string') ?
@ -361,10 +365,13 @@
comment = '',
space = false,
first_attr = true,
has_wrapped_attrs = false,
tag_start, tag_end,
tag_start_char,
orig_pos = this.pos,
orig_line_char_count = this.line_char_count;
orig_line_char_count = this.line_char_count,
is_tag_closed = false,
tail;
peek = peek !== undefined ? peek : false;
@ -388,27 +395,44 @@
if (input_char === "'" || input_char === '"') {
input_char += this.get_unformatted(input_char);
space = true;
}
if (input_char === '=') { //no space before =
space = false;
}
tail = this.input.substr(this.pos - 1);
if (is_wrap_attributes_force_expand_multiline && has_wrapped_attrs && !is_tag_closed && (input_char === '>' || input_char === '/')) {
if (tail.match(/^\/?\s*>/)) {
space = false;
is_tag_closed = true;
this.print_newline(false, content);
this.print_indentation(content);
}
}
if (content.length && content[content.length - 1] !== '=' && input_char !== '>' && space) {
//no space after = or before >
var wrapped = this.space_or_wrap(content);
var indentAttrs = wrapped && input_char !== '/' && !is_wrap_attributes_force;
space = false;
if (!first_attr && is_wrap_attributes_force && input_char !== '/') {
if (is_wrap_attributes_force && input_char !== '/') {
var force_first_attr_wrap = false;
if (is_wrap_attributes_force_expand_multiline && first_attr) {
var is_only_attribute = tail.match(/^\S*(="([^"]|\\")*")?\s*\/?\s*>/) !== null;
force_first_attr_wrap = !is_only_attribute;
}
if (!first_attr || force_first_attr_wrap) {
this.print_newline(false, content);
this.print_indentation(content);
indentAttrs = true;
}
}
if (indentAttrs) {
has_wrapped_attrs = true;
//indent attributes an auto, forced, or forced-align line-wrap
var alignment_size = wrap_attributes_indent_size;
if (wrap_attributes === 'force-aligned') {
if (is_wrap_attributes_force_aligned) {
alignment_size = content.indexOf(' ') + 1;
}
@ -416,6 +440,7 @@
content.push(indent_character);
}
}
if (first_attr) {
for (var i = 0; i < content.length; i++) {
if (content[i] === ' ') {
first_attr = false;
@ -423,6 +448,7 @@
}
}
}
}
if (indent_handlebars && tag_start_char === '<') {
// When inside an angle-bracket tag, put spaces around
@ -478,7 +504,9 @@
var tag_index;
var tag_offset;
if (tag_complete.indexOf(' ') !== -1) { //if there's whitespace, thats where the tag name ends
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
tag_index = tag_complete.indexOf(' ');
} else if (tag_complete.charAt(0) === '{') {
tag_index = tag_complete.indexOf('}');

View File

@ -258,87 +258,139 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
reset_options();
//============================================================
// Attribute Wrap - (indent_attr = "\n ", indent_over80 = "\n ")
// Attribute Wrap - (indent_attr = "\n ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")
opts.wrap_attributes = 'force';
test_fragment('<div >This is some text</div>', '<div>This is some text</div>');
test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');
test_fragment('<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>', '<div attr0\n attr1="123"\n data-attr2="hello t here">This is some text</div>');
test_fragment('<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>', '<div lookatthissuperduperlongattributenamewhoahcrazy0="true"\n attr0\n attr1="123"\n data-attr2="hello t here"\n heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>');
test_fragment('<img attr0 attr1="123" data-attr2="hello t here"/>', '<img attr0\n attr1="123"\n data-attr2="hello t here" />');
test_fragment('<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>', '<?xml version="1.0" encoding="UTF-8" ?>\n<root attr1="foo"\n attr2="bar" />');
test_fragment('<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">', '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n rel="stylesheet"\n type="text/css">');
// Attribute Wrap - (indent_attr = "\n ", indent_over80 = "\n ")
// Attribute Wrap - (indent_attr = "\n ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")
opts.wrap_attributes = 'force';
opts.wrap_line_length = 80;
test_fragment('<div >This is some text</div>', '<div>This is some text</div>');
test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');
test_fragment('<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>', '<div attr0\n attr1="123"\n data-attr2="hello t here">This is some text</div>');
test_fragment('<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>', '<div lookatthissuperduperlongattributenamewhoahcrazy0="true"\n attr0\n attr1="123"\n data-attr2="hello t here"\n heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>');
test_fragment('<img attr0 attr1="123" data-attr2="hello t here"/>', '<img attr0\n attr1="123"\n data-attr2="hello t here" />');
test_fragment('<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>', '<?xml version="1.0" encoding="UTF-8" ?>\n<root attr1="foo"\n attr2="bar" />');
test_fragment('<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">', '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n rel="stylesheet"\n type="text/css">');
// Attribute Wrap - (indent_attr = "\n ", indent_over80 = "\n ")
// Attribute Wrap - (indent_attr = "\n ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")
opts.wrap_attributes = 'force';
opts.wrap_attributes_indent_size = 8;
test_fragment('<div >This is some text</div>', '<div>This is some text</div>');
test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');
test_fragment('<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>', '<div attr0\n attr1="123"\n data-attr2="hello t here">This is some text</div>');
test_fragment('<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>', '<div lookatthissuperduperlongattributenamewhoahcrazy0="true"\n attr0\n attr1="123"\n data-attr2="hello t here"\n heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>');
test_fragment('<img attr0 attr1="123" data-attr2="hello t here"/>', '<img attr0\n attr1="123"\n data-attr2="hello t here" />');
test_fragment('<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>', '<?xml version="1.0" encoding="UTF-8" ?>\n<root attr1="foo"\n attr2="bar" />');
test_fragment('<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">', '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n rel="stylesheet"\n type="text/css">');
// Attribute Wrap - (indent_attr = " ", indent_over80 = "\n")
// Attribute Wrap - (indent_attr = " ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n")
opts.wrap_attributes = 'auto';
opts.wrap_line_length = 80;
opts.wrap_attributes_indent_size = 0;
test_fragment('<div >This is some text</div>', '<div>This is some text</div>');
test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');
test_fragment('<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>');
test_fragment('<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>', '<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here"\nheymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>');
test_fragment('<img attr0 attr1="123" data-attr2="hello t here"/>', '<img attr0 attr1="123" data-attr2="hello t here" />');
test_fragment('<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>', '<?xml version="1.0" encoding="UTF-8" ?>\n<root attr1="foo" attr2="bar" />');
test_fragment('<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">', '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\nrel="stylesheet" type="text/css">');
// Attribute Wrap - (indent_attr = " ", indent_over80 = "\n ")
// Attribute Wrap - (indent_attr = " ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")
opts.wrap_attributes = 'auto';
opts.wrap_line_length = 80;
opts.wrap_attributes_indent_size = 4;
test_fragment('<div >This is some text</div>', '<div>This is some text</div>');
test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');
test_fragment('<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>');
test_fragment('<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>', '<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here"\n heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>');
test_fragment('<img attr0 attr1="123" data-attr2="hello t here"/>', '<img attr0 attr1="123" data-attr2="hello t here" />');
test_fragment('<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>', '<?xml version="1.0" encoding="UTF-8" ?>\n<root attr1="foo" attr2="bar" />');
test_fragment('<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">', '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n rel="stylesheet" type="text/css">');
// Attribute Wrap - (indent_attr = " ", indent_over80 = " ")
// Attribute Wrap - (indent_attr = " ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = " ")
opts.wrap_attributes = 'auto';
opts.wrap_line_length = 0;
test_fragment('<div >This is some text</div>', '<div>This is some text</div>');
test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');
test_fragment('<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>');
test_fragment('<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>');
test_fragment('<img attr0 attr1="123" data-attr2="hello t here"/>', '<img attr0 attr1="123" data-attr2="hello t here" />');
test_fragment('<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>', '<?xml version="1.0" encoding="UTF-8" ?>\n<root attr1="foo" attr2="bar" />');
test_fragment('<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">');
// Attribute Wrap - (indent_attr = "\n ", indent_attr_faligned = " ", indent_over80 = "\n ")
// Attribute Wrap - (indent_attr = "\n ", indent_attr_faligned = " ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")
opts.wrap_attributes = 'force-aligned';
test_fragment('<div >This is some text</div>', '<div>This is some text</div>');
test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');
test_fragment('<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>', '<div attr0\n attr1="123"\n data-attr2="hello t here">This is some text</div>');
test_fragment('<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>', '<div lookatthissuperduperlongattributenamewhoahcrazy0="true"\n attr0\n attr1="123"\n data-attr2="hello t here"\n heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>');
test_fragment('<img attr0 attr1="123" data-attr2="hello t here"/>', '<img attr0\n attr1="123"\n data-attr2="hello t here" />');
test_fragment('<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>', '<?xml version="1.0" encoding="UTF-8" ?>\n<root attr1="foo"\n attr2="bar" />');
test_fragment('<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">', '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n rel="stylesheet"\n type="text/css">');
// Attribute Wrap - (indent_attr = "\n ", indent_attr_faligned = " ", indent_over80 = "\n ")
// Attribute Wrap - (indent_attr = "\n ", indent_attr_faligned = " ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")
opts.wrap_attributes = 'force-aligned';
opts.wrap_line_length = 80;
test_fragment('<div >This is some text</div>', '<div>This is some text</div>');
test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');
test_fragment('<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>', '<div attr0\n attr1="123"\n data-attr2="hello t here">This is some text</div>');
test_fragment('<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>', '<div lookatthissuperduperlongattributenamewhoahcrazy0="true"\n attr0\n attr1="123"\n data-attr2="hello t here"\n heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>');
test_fragment('<img attr0 attr1="123" data-attr2="hello t here"/>', '<img attr0\n attr1="123"\n data-attr2="hello t here" />');
test_fragment('<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>', '<?xml version="1.0" encoding="UTF-8" ?>\n<root attr1="foo"\n attr2="bar" />');
test_fragment('<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">', '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n rel="stylesheet"\n type="text/css">');
// Attribute Wrap - (indent_attr = "\n ", indent_attr_faligned = " ", indent_over80 = "\n ")
// Attribute Wrap - (indent_attr = "\n ", indent_attr_faligned = " ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")
opts.wrap_attributes = 'force-aligned';
opts.wrap_attributes_indent_size = 8;
test_fragment('<div >This is some text</div>', '<div>This is some text</div>');
test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');
test_fragment('<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>', '<div attr0\n attr1="123"\n data-attr2="hello t here">This is some text</div>');
test_fragment('<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>', '<div lookatthissuperduperlongattributenamewhoahcrazy0="true"\n attr0\n attr1="123"\n data-attr2="hello t here"\n heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>');
test_fragment('<img attr0 attr1="123" data-attr2="hello t here"/>', '<img attr0\n attr1="123"\n data-attr2="hello t here" />');
test_fragment('<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>', '<?xml version="1.0" encoding="UTF-8" ?>\n<root attr1="foo"\n attr2="bar" />');
test_fragment('<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">', '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n rel="stylesheet"\n type="text/css">');
// Attribute Wrap - (indent_attr = "\n ", indent_attr_first = "\n ", indent_end = "\n", indent_end_selfclosing = "\n", indent_over80 = "\n ")
opts.wrap_attributes = 'force-expand-multiline';
opts.wrap_attributes_indent_size = 4;
test_fragment('<div >This is some text</div>', '<div>This is some text</div>');
test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');
test_fragment('<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>', '<div\n attr0\n attr1="123"\n data-attr2="hello t here"\n>This is some text</div>');
test_fragment('<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>', '<div\n lookatthissuperduperlongattributenamewhoahcrazy0="true"\n attr0\n attr1="123"\n data-attr2="hello t here"\n heymanimreallylongtoowhocomesupwiththesenames="false"\n>This is some text</div>');
test_fragment('<img attr0 attr1="123" data-attr2="hello t here"/>', '<img\n attr0\n attr1="123"\n data-attr2="hello t here"\n/>');
test_fragment('<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>', '<?xml version="1.0" encoding="UTF-8" ?>\n<root\n attr1="foo"\n attr2="bar"\n/>');
test_fragment('<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">', '<link\n href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n rel="stylesheet"\n type="text/css"\n>');
// Attribute Wrap - (indent_attr = "\n ", indent_attr_first = "\n ", indent_end = "\n", indent_end_selfclosing = "\n", indent_over80 = "\n ")
opts.wrap_attributes = 'force-expand-multiline';
opts.wrap_attributes_indent_size = 4;
opts.wrap_line_length = 80;
test_fragment('<div >This is some text</div>', '<div>This is some text</div>');
test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');
test_fragment('<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>', '<div\n attr0\n attr1="123"\n data-attr2="hello t here"\n>This is some text</div>');
test_fragment('<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>', '<div\n lookatthissuperduperlongattributenamewhoahcrazy0="true"\n attr0\n attr1="123"\n data-attr2="hello t here"\n heymanimreallylongtoowhocomesupwiththesenames="false"\n>This is some text</div>');
test_fragment('<img attr0 attr1="123" data-attr2="hello t here"/>', '<img\n attr0\n attr1="123"\n data-attr2="hello t here"\n/>');
test_fragment('<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>', '<?xml version="1.0" encoding="UTF-8" ?>\n<root\n attr1="foo"\n attr2="bar"\n/>');
test_fragment('<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">', '<link\n href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n rel="stylesheet"\n type="text/css"\n>');
// Attribute Wrap - (indent_attr = "\n ", indent_attr_first = "\n ", indent_end = "\n", indent_end_selfclosing = "\n", indent_over80 = "\n ")
opts.wrap_attributes = 'force-expand-multiline';
opts.wrap_attributes_indent_size = 8;
test_fragment('<div >This is some text</div>', '<div>This is some text</div>');
test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');
test_fragment('<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>', '<div\n attr0\n attr1="123"\n data-attr2="hello t here"\n>This is some text</div>');
test_fragment('<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>', '<div\n lookatthissuperduperlongattributenamewhoahcrazy0="true"\n attr0\n attr1="123"\n data-attr2="hello t here"\n heymanimreallylongtoowhocomesupwiththesenames="false"\n>This is some text</div>');
test_fragment('<img attr0 attr1="123" data-attr2="hello t here"/>', '<img\n attr0\n attr1="123"\n data-attr2="hello t here"\n/>');
test_fragment('<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>', '<?xml version="1.0" encoding="UTF-8" ?>\n<root\n attr1="foo"\n attr2="bar"\n/>');
test_fragment('<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">', '<link\n href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n rel="stylesheet"\n type="text/css"\n>');
reset_options();
//============================================================

View File

@ -262,6 +262,9 @@ exports.test_data = {
{ name: "wrap_attributes", value: "'force'" }
],
indent_attr: '\\n ',
indent_attr_first: ' ',
indent_end: '',
indent_end_selfclosing: ' ',
indent_over80: '\\n '
}, {
options: [
@ -269,6 +272,9 @@ exports.test_data = {
{ name: "wrap_line_length", value: "80" }
],
indent_attr: '\\n ',
indent_attr_first: ' ',
indent_end: '',
indent_end_selfclosing: ' ',
indent_over80: '\\n '
}, {
options: [
@ -276,6 +282,9 @@ exports.test_data = {
{ name: "wrap_attributes_indent_size", value: "8" }
],
indent_attr: '\\n ',
indent_attr_first: ' ',
indent_end: '',
indent_end_selfclosing: ' ',
indent_over80: '\\n '
}, {
options: [
@ -284,6 +293,9 @@ exports.test_data = {
{ name: "wrap_attributes_indent_size", value: "0" }
],
indent_attr: ' ',
indent_attr_first: ' ',
indent_end: '',
indent_end_selfclosing: ' ',
indent_over80: '\\n'
}, {
options: [
@ -292,6 +304,9 @@ exports.test_data = {
{ name: "wrap_attributes_indent_size", value: "4" }
],
indent_attr: ' ',
indent_attr_first: ' ',
indent_end: '',
indent_end_selfclosing: ' ',
indent_over80: '\\n '
}, {
options: [
@ -299,6 +314,9 @@ exports.test_data = {
{ name: "wrap_line_length", value: "0" }
],
indent_attr: ' ',
indent_attr_first: ' ',
indent_end: '',
indent_end_selfclosing: ' ',
indent_over80: ' '
}, {
options: [
@ -306,6 +324,9 @@ exports.test_data = {
],
indent_attr: '\\n ',
indent_attr_faligned: ' ',
indent_attr_first: ' ',
indent_end: '',
indent_end_selfclosing: ' ',
indent_over80: '\\n '
}, {
options: [
@ -314,6 +335,9 @@ exports.test_data = {
],
indent_attr: '\\n ',
indent_attr_faligned: ' ',
indent_attr_first: ' ',
indent_end: '',
indent_end_selfclosing: ' ',
indent_over80: '\\n '
}, {
options: [
@ -322,28 +346,70 @@ exports.test_data = {
],
indent_attr: '\\n ',
indent_attr_faligned: ' ',
indent_attr_first: ' ',
indent_end: '',
indent_end_selfclosing: ' ',
indent_over80: '\\n '
}, {
options: [
{ name: "wrap_attributes", value: "'force-expand-multiline'" },
{ name: "wrap_attributes_indent_size", value: "4" }
],
indent_attr: '\\n ',
indent_attr_first: '\\n ',
indent_end: '\\n',
indent_end_selfclosing: '\\n',
indent_over80: '\\n '
}, {
options: [
{ name: "wrap_attributes", value: "'force-expand-multiline'" },
{ name: "wrap_attributes_indent_size", value: "4" },
{ name: "wrap_line_length", value: "80" }
],
indent_attr: '\\n ',
indent_attr_first: '\\n ',
indent_end: '\\n',
indent_end_selfclosing: '\\n',
indent_over80: '\\n '
}, {
options: [
{ name: "wrap_attributes", value: "'force-expand-multiline'" },
{ name: "wrap_attributes_indent_size", value: "8" }
],
indent_attr: '\\n ',
indent_attr_first: '\\n ',
indent_end: '\\n',
indent_end_selfclosing: '\\n',
indent_over80: '\\n '
}],
tests: [{
fragment: true,
input: '<div >This is some text</div>',
output: '<div>This is some text</div>'
}, {
fragment: true,
input: '<div attr="123" >This is some text</div>',
output: '<div attr="123">This is some text</div>'
}, {
fragment: true,
input: '<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>',
output: '<div attr0{{indent_attr}}attr1="123"{{indent_attr}}data-attr2="hello t here">This is some text</div>'
output: '<div{{indent_attr_first}}attr0{{indent_attr}}attr1="123"{{indent_attr}}data-attr2="hello t here"{{indent_end}}>This is some text</div>'
}, {
fragment: true,
input: '<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>',
output: '<div lookatthissuperduperlongattributenamewhoahcrazy0="true"{{indent_attr}}attr0{{indent_attr}}attr1="123"{{indent_attr}}data-attr2="hello t here"{{indent_over80}}heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>'
output: '<div{{indent_attr_first}}lookatthissuperduperlongattributenamewhoahcrazy0="true"{{indent_attr}}attr0{{indent_attr}}attr1="123"{{indent_attr}}data-attr2="hello t here"{{indent_over80}}heymanimreallylongtoowhocomesupwiththesenames="false"{{indent_end}}>This is some text</div>'
}, {
fragment: true,
input: '<img attr0 attr1="123" data-attr2="hello t here"/>',
output: '<img attr0{{indent_attr}}attr1="123"{{indent_attr}}data-attr2="hello t here" />'
output: '<img{{indent_attr_first}}attr0{{indent_attr}}attr1="123"{{indent_attr}}data-attr2="hello t here"{{indent_end_selfclosing}}/>'
}, {
fragment: true,
input: '<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>',
output: '<?xml version="1.0" encoding="UTF-8" ?>\n<root attr1="foo"{{indent_attr}}{{indent_attr_faligned}}attr2="bar" />'
output: '<?xml version="1.0" encoding="UTF-8" ?>\n<root{{indent_attr_first}}attr1="foo"{{indent_attr}}{{indent_attr_faligned}}attr2="bar"{{indent_end_selfclosing}}/>'
}, {
fragment: true,
input: '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">',
output: '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"{{indent_over80}}{{indent_attr_faligned}}rel="stylesheet"{{indent_attr}}{{indent_attr_faligned}}type="text/css">'
output: '<link{{indent_attr_first}}href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"{{indent_over80}}{{indent_attr_faligned}}rel="stylesheet"{{indent_attr}}{{indent_attr_faligned}}type="text/css"{{indent_end}}>'
}]
}, {
name: "Handlebars Indenting Off",