@kademi/keditor
Version:
KEditor is a jQuery plugin which provides a content editor with drag n drop, configurable contents
1,111 lines (1,054 loc) • 126 kB
JavaScript
/*
AUTO-GENERATED. DO NOT MODIFY.
Script: test/generate-tests.js
Template: test/data/html/node.mustache
Data: test/data/html/tests.js
The MIT License (MIT)
Copyright (c) 2007-2017 Einar Lielmanis, Liam Newman, and contributors.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*jshint unused:false */
function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_beautify)
{
var default_opts = {
indent_size: 4,
indent_char: ' ',
preserve_newlines: true,
jslint_happy: false,
keep_array_indentation: false,
brace_style: 'collapse',
space_before_conditional: true,
break_chained_methods: false,
selector_separator: '\n',
end_with_newline: false
};
var opts;
default_opts.indent_size = 4;
default_opts.indent_char = ' ';
default_opts.indent_with_tabs = false;
default_opts.preserve_newlines = true;
default_opts.jslint_happy = false;
default_opts.keep_array_indentation = false;
default_opts.brace_style = 'collapse';
default_opts.extra_liners = ['html', 'head', '/html'];
function reset_options()
{
opts = JSON.parse(JSON.stringify(default_opts));
}
function test_html_beautifier(input)
{
return html_beautify(input, opts);
}
var sanitytest;
// test the input on beautifier with the current flag settings
// does not check the indentation / surroundings as bt() does
function test_fragment(input, expected)
{
expected = expected || expected === '' ? expected : input;
sanitytest.expect(input, expected);
// if the expected is different from input, run it again
// expected output should be unchanged when run twice.
if (expected !== input) {
sanitytest.expect(expected, expected);
}
// Everywhere we do newlines, they should be replaced with opts.eol
opts.eol = '\r\n';
expected = expected.replace(/[\n]/g, '\r\n');
sanitytest.expect(input, expected);
if (input.indexOf('\n') !== -1) {
input = input.replace(/[\n]/g, '\r\n');
sanitytest.expect(input, expected);
// Ensure support for auto eol detection
opts.eol = 'auto';
sanitytest.expect(input, expected);
}
opts.eol = '\n';
}
// test html
function bth(input, expectation)
{
var wrapped_input, wrapped_expectation, field_input, field_expectation;
expectation = expectation || expectation === '' ? expectation : input;
sanitytest.test_function(test_html_beautifier, 'html_beautify');
test_fragment(input, expectation);
if (opts.indent_size === 4 && input) {
wrapped_input = '<div>\n' + input.replace(/^(.+)$/mg, ' $1') + '\n <span>inline</span>\n</div>';
wrapped_expectation = '<div>\n' + expectation.replace(/^(.+)$/mg, ' $1') + '\n <span>inline</span>\n</div>';
test_fragment(wrapped_input, wrapped_expectation);
}
}
function unicode_char(value) {
return String.fromCharCode(value);
}
function beautifier_tests()
{
sanitytest = test_obj;
reset_options();
//============================================================
bth('');
//============================================================
// Handle inline and block elements differently - ()
reset_options();
test_fragment(
'<body><h1>Block</h1></body>',
// -- output --
'<body>\n' +
' <h1>Block</h1>\n' +
'</body>');
test_fragment('<body><i>Inline</i></body>');
//============================================================
// End With Newline - (eof = "\n")
reset_options();
opts.end_with_newline = true;
test_fragment('', '\n');
test_fragment('<div></div>', '<div></div>\n');
test_fragment('\n');
// End With Newline - (eof = "")
reset_options();
opts.end_with_newline = false;
test_fragment('');
test_fragment('<div></div>');
test_fragment('\n', '');
//============================================================
// Custom Extra Liners (empty) - ()
reset_options();
opts.extra_liners = [];
test_fragment(
'<html><head><meta></head><body><div><p>x</p></div></body></html>',
// -- output --
'<html>\n' +
'<head>\n' +
' <meta>\n' +
'</head>\n' +
'<body>\n' +
' <div>\n' +
' <p>x</p>\n' +
' </div>\n' +
'</body>\n' +
'</html>');
//============================================================
// Custom Extra Liners (default) - ()
reset_options();
opts.extra_liners = null;
test_fragment(
'<html><head></head><body></body></html>',
// -- output --
'<html>\n' +
'\n' +
'<head></head>\n' +
'\n' +
'<body></body>\n' +
'\n' +
'</html>');
//============================================================
// Custom Extra Liners (p, string) - ()
reset_options();
opts.extra_liners = 'p,/p';
test_fragment(
'<html><head><meta></head><body><div><p>x</p></div></body></html>',
// -- output --
'<html>\n' +
'<head>\n' +
' <meta>\n' +
'</head>\n' +
'<body>\n' +
' <div>\n' +
'\n' +
' <p>x\n' +
'\n' +
' </p>\n' +
' </div>\n' +
'</body>\n' +
'</html>');
//============================================================
// Custom Extra Liners (p) - ()
reset_options();
opts.extra_liners = ['p', '/p'];
test_fragment(
'<html><head><meta></head><body><div><p>x</p></div></body></html>',
// -- output --
'<html>\n' +
'<head>\n' +
' <meta>\n' +
'</head>\n' +
'<body>\n' +
' <div>\n' +
'\n' +
' <p>x\n' +
'\n' +
' </p>\n' +
' </div>\n' +
'</body>\n' +
'</html>');
//============================================================
// Tests for script and style types (issue 453, 821)
reset_options();
bth(
'<script type="text/unknown"><div></div></script>',
// -- output --
'<script type="text/unknown">\n' +
' <div></div>\n' +
'</script>');
bth(
'<script type="text/javascript"><div></div></script>',
// -- output --
'<script type="text/javascript">\n' +
' < div > < /div>\n' +
'</script>');
bth(
'<script><div></div></script>',
// -- output --
'<script>\n' +
' < div > < /div>\n' +
'</script>');
bth(
'<script>var foo = "bar";</script>',
// -- output --
'<script>\n' +
' var foo = "bar";\n' +
'</script>');
bth(
'<script type="text/javascript">var foo = "bar";</script>',
// -- output --
'<script type="text/javascript">\n' +
' var foo = "bar";\n' +
'</script>');
bth(
'<script type="application/javascript">var foo = "bar";</script>',
// -- output --
'<script type="application/javascript">\n' +
' var foo = "bar";\n' +
'</script>');
bth(
'<script type="application/javascript;version=1.8">var foo = "bar";</script>',
// -- output --
'<script type="application/javascript;version=1.8">\n' +
' var foo = "bar";\n' +
'</script>');
bth(
'<script type="application/x-javascript">var foo = "bar";</script>',
// -- output --
'<script type="application/x-javascript">\n' +
' var foo = "bar";\n' +
'</script>');
bth(
'<script type="application/ecmascript">var foo = "bar";</script>',
// -- output --
'<script type="application/ecmascript">\n' +
' var foo = "bar";\n' +
'</script>');
bth(
'<script type="dojo/aspect">this.domNode.style.display="none";</script>',
// -- output --
'<script type="dojo/aspect">\n' +
' this.domNode.style.display = "none";\n' +
'</script>');
bth(
'<script type="dojo/method">this.domNode.style.display="none";</script>',
// -- output --
'<script type="dojo/method">\n' +
' this.domNode.style.display = "none";\n' +
'</script>');
bth(
'<script type="text/javascript1.5">var foo = "bar";</script>',
// -- output --
'<script type="text/javascript1.5">\n' +
' var foo = "bar";\n' +
'</script>');
bth(
'<script type="application/json">{"foo":"bar"}</script>',
// -- output --
'<script type="application/json">\n' +
' {\n' +
' "foo": "bar"\n' +
' }\n' +
'</script>');
bth(
'<script type="application/ld+json">{"foo":"bar"}</script>',
// -- output --
'<script type="application/ld+json">\n' +
' {\n' +
' "foo": "bar"\n' +
' }\n' +
'</script>');
bth(
'<style type="text/unknown"><tag></tag></style>',
// -- output --
'<style type="text/unknown">\n' +
' <tag></tag>\n' +
'</style>');
bth(
'<style type="text/css"><tag></tag></style>',
// -- output --
'<style type="text/css">\n' +
' <tag></tag>\n' +
'</style>');
bth(
'<style><tag></tag></style>',
// -- output --
'<style>\n' +
' <tag></tag>\n' +
'</style>');
bth(
'<style>.selector {font-size:12px;}</style>',
// -- output --
'<style>\n' +
' .selector {\n' +
' font-size: 12px;\n' +
' }\n' +
'</style>');
bth(
'<style type="text/css">.selector {font-size:12px;}</style>',
// -- output --
'<style type="text/css">\n' +
' .selector {\n' +
' font-size: 12px;\n' +
' }\n' +
'</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>',
// -- output --
'<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;
test_fragment(
'<div a="1" b="2"><div>test</div></div>',
// -- output --
'<div a="1"\n' +
' b="2">\n' +
' <div>test</div>\n' +
'</div>');
test_fragment(
'<p>\n' +
' <a href="/test/" target="_blank"><img src="test.jpg" /></a><a href="/test/" target="_blank"><img src="test.jpg" /></a>\n' +
'</p>',
// -- output --
'<p>\n' +
' <a href="/test/"\n' +
' target="_blank"><img src="test.jpg" /></a><a href="/test/"\n' +
' target="_blank"><img src="test.jpg" /></a>\n' +
'</p>');
test_fragment(
'<p>\n' +
' <span data-not-a-href="/test/" data-totally-not-a-target="_blank"><img src="test.jpg" /></span><span data-not-a-href="/test/" data-totally-not-a-target="_blank"><img src="test.jpg" /></span>\n' +
'</p>',
// -- output --
'<p>\n' +
' <span data-not-a-href="/test/"\n' +
' data-totally-not-a-target="_blank"><img src="test.jpg" /></span><span data-not-a-href="/test/"\n' +
' data-totally-not-a-target="_blank"><img src="test.jpg" /></span>\n' +
'</p>');
//============================================================
// Attribute Wrap - (indent_attr = "\n ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")
reset_options();
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>',
// -- output --
'<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>',
// -- output --
'<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"/>',
// -- output --
'<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"/>',
// -- output --
'<?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&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&subset=latin"\n' +
' rel="stylesheet"\n' +
' type="text/css">');
// Attribute Wrap - (indent_attr = "\n ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")
reset_options();
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>',
// -- output --
'<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>',
// -- output --
'<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"/>',
// -- output --
'<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"/>',
// -- output --
'<?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&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&subset=latin"\n' +
' rel="stylesheet"\n' +
' type="text/css">');
// Attribute Wrap - (indent_attr = "\n ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")
reset_options();
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>',
// -- output --
'<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>',
// -- output --
'<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"/>',
// -- output --
'<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"/>',
// -- output --
'<?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&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&subset=latin"\n' +
' rel="stylesheet"\n' +
' type="text/css">');
// Attribute Wrap - (indent_attr = " ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n")
reset_options();
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>',
// -- output --
'<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"/>',
// -- output --
'<?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&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&subset=latin"\n' +
'rel="stylesheet" type="text/css">');
// Attribute Wrap - (indent_attr = " ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")
reset_options();
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>',
// -- output --
'<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"/>',
// -- output --
'<?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&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&subset=latin"\n' +
' rel="stylesheet" type="text/css">');
// Attribute Wrap - (indent_attr = " ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = " ")
reset_options();
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"/>',
// -- output --
'<?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&subset=latin" rel="stylesheet" type="text/css">');
// Attribute Wrap - (indent_attr = "\n ", indent_attr_faligned = " ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")
reset_options();
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>',
// -- output --
'<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>',
// -- output --
'<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"/>',
// -- output --
'<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"/>',
// -- output --
'<?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&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&subset=latin"\n' +
' rel="stylesheet"\n' +
' type="text/css">');
// Attribute Wrap - (indent_attr = "\n ", indent_attr_faligned = " ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")
reset_options();
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>',
// -- output --
'<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>',
// -- output --
'<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"/>',
// -- output --
'<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"/>',
// -- output --
'<?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&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&subset=latin"\n' +
' rel="stylesheet"\n' +
' type="text/css">');
// Attribute Wrap - (indent_attr = "\n ", indent_attr_faligned = " ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")
reset_options();
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>',
// -- output --
'<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>',
// -- output --
'<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"/>',
// -- output --
'<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"/>',
// -- output --
'<?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&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&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 ")
reset_options();
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>',
// -- output --
'<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>',
// -- output --
'<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"/>',
// -- output --
'<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"/>',
// -- output --
'<?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&subset=latin" rel="stylesheet" type="text/css">',
// -- output --
'<link\n' +
' href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&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 ")
reset_options();
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>',
// -- output --
'<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>',
// -- output --
'<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"/>',
// -- output --
'<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"/>',
// -- output --
'<?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&subset=latin" rel="stylesheet" type="text/css">',
// -- output --
'<link\n' +
' href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&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 ")
reset_options();
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>',
// -- output --
'<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>',
// -- output --
'<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"/>',
// -- output --
'<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"/>',
// -- output --
'<?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&subset=latin" rel="stylesheet" type="text/css">',
// -- output --
'<link\n' +
' href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&subset=latin"\n' +
' rel="stylesheet"\n' +
' type="text/css"\n' +
'>');
//============================================================
// Handlebars Indenting Off
reset_options();
opts.indent_handlebars = false;
test_fragment(
'{{#if 0}}\n' +
' <div>\n' +
' </div>\n' +
'{{/if}}',
// -- output --
'{{#if 0}}\n' +
'<div>\n' +
'</div>\n' +
'{{/if}}');
test_fragment(
'<div>\n' +
'{{#each thing}}\n' +
' {{name}}\n' +
'{{/each}}\n' +
'</div>',
// -- output --
'<div>\n' +
' {{#each thing}} {{name}} {{/each}}\n' +
'</div>');
//============================================================
// Handlebars Indenting On - (content = "{{field}}")
reset_options();
opts.indent_handlebars = true;
test_fragment('{{page-title}}');
test_fragment('{{#if 0}}{{/if}}');
test_fragment('{{#if 0}}{{field}}{{/if}}');
test_fragment(
'{{#if 0}}\n' +
'{{/if}}');
test_fragment(
'{{#if words}}{{/if}}',
// -- output --
'{{#if words}}{{/if}}');
test_fragment(
'{{#if words}}{{field}}{{/if}}',
// -- output --
'{{#if words}}{{field}}{{/if}}');
test_fragment(
'{{#if words}}{{field}}{{/if}}',
// -- output --
'{{#if words}}{{field}}{{/if}}');
test_fragment(
'{{#if 1}}\n' +
' <div>\n' +
' </div>\n' +
'{{/if}}');
test_fragment(
'{{#if 1}}\n' +
'<div>\n' +
'</div>\n' +
'{{/if}}',
// -- output --
'{{#if 1}}\n' +
' <div>\n' +
' </div>\n' +
'{{/if}}');
test_fragment(
'<div>\n' +
' {{#if 1}}\n' +
' {{/if}}\n' +
'</div>');
test_fragment(
'<div>\n' +
'{{#if 1}}\n' +
'{{/if}}\n' +
'</div>',
// -- output --
'<div>\n' +
' {{#if 1}}\n' +
' {{/if}}\n' +
'</div>');
test_fragment(
'{{#if}}\n' +
'{{#each}}\n' +
'{{#if}}\n' +
'{{field}}\n' +
'{{/if}}\n' +
'{{#if}}\n' +
'{{field}}\n' +
'{{/if}}\n' +
'{{/each}}\n' +
'{{/if}}',
// -- output --
'{{#if}}\n' +
' {{#each}}\n' +
' {{#if}}\n' +
' {{field}}\n' +
' {{/if}}\n' +
' {{#if}}\n' +
' {{field}}\n' +
' {{/if}}\n' +
' {{/each}}\n' +
'{{/if}}');
test_fragment(
'{{#if 1}}\n' +
' <div>\n' +
' </div>\n' +
'{{/if}}');
test_fragment(
'{{#if 1}}\n' +
' {{field}}\n' +
' {{else}}\n' +
' {{field}}\n' +
'{{/if}}',
// -- output --
'{{#if 1}}\n' +
' {{field}}\n' +
'{{else}}\n' +
' {{field}}\n' +
'{{/if}}');
test_fragment(
'{{#if 1}}\n' +
' {{else}}\n' +
' {{/if}}',
// -- output --
'{{#if 1}}\n' +
'{{else}}\n' +
'{{/if}}');
test_fragment(
'{{#if thing}}\n' +
'{{#if otherthing}}\n' +
' {{field}}\n' +
' {{else}}\n' +
'{{field}}\n' +
' {{/if}}\n' +
' {{else}}\n' +
'{{field}}\n' +
'{{/if}}',
// -- output --
'{{#if thing}}\n' +
' {{#if otherthing}}\n' +
' {{field}}\n' +
' {{else}}\n' +
' {{field}}\n' +
' {{/if}}\n' +
'{{else}}\n' +
' {{field}}\n' +
'{{/if}}');
test_fragment(
'<div{{somestyle}}></div>',
// -- output --
'<div {{somestyle}}></div>');
test_fragment(
'<div{{#if test}}class="foo"{{/if}}>{{field}}</div>',
// -- output --
'<div {{#if test}} class="foo" {{/if}}>{{field}}</div>');
test_fragment(
'<div{{#if thing}}{{somestyle}}class="{{class}}"{{else}}class="{{class2}}"{{/if}}>{{field}}</div>',
// -- output --
'<div {{#if thing}} {{somestyle}} class="{{class}}" {{else}} class="{{class2}}" {{/if}}>{{field}}</div>');
test_fragment(
'<span{{#if condition}}class="foo"{{/if}}>{{field}}</span>',
// -- output --
'<span {{#if condition}} class="foo" {{/if}}>{{field}}</span>');
test_fragment('<div unformatted="{{#if}}{{field}}{{/if}}">{{field}}</div>');
test_fragment('<div unformatted="{{#if }} {{field}}{{/if}}">{{field}}</div>');
test_fragment('<div class="{{#if thingIs "value"}}{{field}}{{/if}}"></div>');
test_fragment('<div class="{{#if thingIs \'value\'}}{{field}}{{/if}}"></div>');
test_fragment('<div class=\'{{#if thingIs "value"}}{{field}}{{/if}}\'></div>');
test_fragment('<div class=\'{{#if thingIs \'value\'}}{{field}}{{/if}}\'></div>');
test_fragment('<span>{{condition < 0 ? "result1" : "result2"}}</span>');
test_fragment('<span>{{condition1 && condition2 && condition3 && condition4 < 0 ? "resForTrue" : "resForFalse"}}</span>');
// Handlebars Indenting On - (content = "{{! comment}}")
reset_options();
opts.indent_handlebars = true;
test_fragment('{{page-title}}');
test_fragment('{{#if 0}}{{/if}}');
test_fragment('{{#if 0}}{{! comment}}{{/if}}');
test_fragment(
'{{#if 0}}\n' +
'{{/if}}');
test_fragment(
'{{#if words}}{{/if}}',
// -- output --
'{{#if words}}{{/if}}');
test_fragment(
'{{#if words}}{{! comment}}{{/if}}',
// -- output --
'{{#if words}}{{! comment}}{{/if}}');
test_fragment(
'{{#if words}}{{! comment}}{{/if}}',
// -- output --
'{{#if words}}{{! comment}}{{/if}}');
test_fragment(
'{{#if 1}}\n' +
' <div>\n' +
' </div>\n' +
'{{/if}}');
test_fragment(
'{{#if 1}}\n' +
'<div>\n' +
'</div>\n' +
'{{/if}}',
// -- output --
'{{#if 1}}\n' +
' <div>\n' +
' </div>\n' +
'{{/if}}');
test_fragment(
'<div>\n' +
' {{#if 1}}\n' +
' {{/if}}\n' +
'</div>');
test_fragment(
'<div>\n' +
'{{#if 1}}\n' +
'{{/if}}\n' +
'</div>',
// -- output --
'<div>\n' +
' {{#if 1}}\n' +
' {{/if}}\n' +
'</div>');
test_fragment(
'{{#if}}\n' +
'{{#each}}\n' +
'{{#if}}\n' +
'{{! comment}}\n' +
'{{/if}}\n' +
'{{#if}}\n' +
'{{! comment}}\n' +
'{{/if}}\n' +
'{{/each}}\n' +
'{{/if}}',
// -- output --
'{{#if}}\n' +
' {{#each}}\n' +
' {{#if}}\n' +
' {{! comment}}\n' +
' {{/if}}\n' +
' {{#if}}\n' +
' {{! comment}}\n' +
' {{/if}}\n' +
' {{/each}}\n' +
'{{/if}}');
test_fragment(
'{{#if 1}}\n' +
' <div>\n' +
' </div>\n' +
'{{/if}}');
test_fragment(
'{{#if 1}}\n' +
' {{! comment}}\n' +
' {{else}}\n' +
' {{! comment}}\n' +