Fix multiline tags with line break before whitespace

This commit is contained in:
Sergio Vallejo 2018-02-18 18:34:17 -03:00
parent 8c4f07a64d
commit fcb6085fdc
4 changed files with 19 additions and 0 deletions

View File

@ -649,6 +649,9 @@ function Beautifier(html_source, options, js_beautify, css_beautify) {
// 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(' ');
if (tag_complete.substring(0, tag_index).indexOf('\n') !== -1) { // if there's a line break before the space, thats where the tag name ends
tag_index = tag_complete.indexOf('\n');
}
} 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) === '{') {

View File

@ -501,6 +501,9 @@ function Beautifier(html_source, options, js_beautify, css_beautify) {
// 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(' ');
if (tag_complete.substring(0, tag_index).indexOf('\n') !== -1) { // if there's a line break before the space, thats where the tag name ends
tag_index = tag_complete.indexOf('\n');
}
} 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) === '{') {

View File

@ -2688,6 +2688,11 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
'<?= "A" ?>\n' +
'<?= "B" ?>\n' +
'<?= "C" ?>');
test_fragment(
'<?php\n' +
'echo "A";\n' +
'?>\n' +
'<span>Test</span>');
//============================================================

View File

@ -845,6 +845,14 @@ exports.test_data = {
'<?= "B" ?>',
'<?= "C" ?>'
]
}, {
fragment: true,
unchanged: [
'<?php',
'echo "A";',
'?>',
'<span>Test</span>'
]
}]
}, {
name: "Support simple language specific option inheritance/overriding",