Skip to content

Commit

Permalink
Merge pull request #1158 from jhaines/master
Browse files Browse the repository at this point in the history
Fix Newlines are inserted between anchor tags around images

Fixes #1153
  • Loading branch information
bitwiseman authored Apr 12, 2017
2 parents 4deeb60 + 1b61ba3 commit 3273c6d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
2 changes: 1 addition & 1 deletion js/lib/beautify-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@
// if next_tag comes back but is not an isolated tag, then
// let's treat the 'a' tag as having content
// and respect the unformatted option
if (!tag || this.Utils.in_array(tag, unformatted)) {
if (!tag || this.Utils.in_array(tag[1], unformatted)) {
return true;
} else {
return false;
Expand Down
42 changes: 41 additions & 1 deletion js/test/generated/beautify-html-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,33 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
reset_options();
opts.wrap_attributes = 'force-aligned';
opts.indent_with_tabs = false;
bth(
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>');


//============================================================
Expand Down Expand Up @@ -2590,6 +2610,26 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
'</ul>');
test_fragment('<div class="searchform"><input type="text" value="" name="s" id="s" /><input type="submit" id="searchsubmit" value="Search" /></div>');
test_fragment('<div class="searchform"><input type="text" value="" name="s" id="s"><input type="submit" id="searchsubmit" value="Search"></div>');
test_fragment(
'<p>\n' +
' <a href="/test/"><img src="test.jpg" /></a>\n' +
'</p>');
test_fragment(
'<p>\n' +
' <a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a>\n' +
'</p>');
test_fragment(
'<p>\n' +
' <a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a>\n' +
'</p>');
test_fragment(
'<p>\n' +
' <span>image: <img src="test.jpg" /></span><span>image: <img src="test.jpg" /></span>\n' +
'</p>');
test_fragment(
'<p>\n' +
' <strong>image: <img src="test.jpg" /></strong><strong>image: <img src="test.jpg" /></strong>\n' +
'</p>');


//============================================================
Expand Down
24 changes: 20 additions & 4 deletions test/data/html/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,21 @@ exports.test_data = {
]
}],
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>'
}]
fragment: true,
input: '<div a="1" b="2"><div>test</div></div>',
output: '<div a="1"\n b="2">\n <div>test</div>\n</div>'
},
{
fragment: true,
input: '<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>'
},
{
fragment: true,
input: '<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>'
}
]
}, {
name: "Attribute Wrap",
description: "Wraps attributes inside of html tags",
Expand Down Expand Up @@ -759,6 +770,11 @@ exports.test_data = {
{ fragment: true, unchanged: '<ul>\n <li>\n <span class="octicon octicon-person"></span>\n <a href="/contact/">Kontakt</a>\n </li>\n</ul>' },
{ fragment: true, unchanged: '<div class="searchform"><input type="text" value="" name="s" id="s" /><input type="submit" id="searchsubmit" value="Search" /></div>' },
{ fragment: true, unchanged: '<div class="searchform"><input type="text" value="" name="s" id="s"><input type="submit" id="searchsubmit" value="Search"></div>' },
{ fragment: true, unchanged: '<p>\n <a href="/test/"><img src="test.jpg" /></a>\n</p>' },
{ fragment: true, unchanged: '<p>\n <a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a>\n</p>' },
{ fragment: true, unchanged: '<p>\n <a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a>\n</p>' },
{ fragment: true, unchanged: '<p>\n <span>image: <img src="test.jpg" /></span><span>image: <img src="test.jpg" /></span>\n</p>' },
{ fragment: true, unchanged: '<p>\n <strong>image: <img src="test.jpg" /></strong><strong>image: <img src="test.jpg" /></strong>\n</p>' },
]
}, {
name: "File starting with comment",
Expand Down

0 comments on commit 3273c6d

Please sign in to comment.