Skip to content
Browse files

Print newline before end tag only if the tag has no content and has c…

…hild
  • Loading branch information...
1 parent 6cb62e1 commit d1526920efacd285513ccef763a378ddad7f428f @zhizhangchen zhizhangchen committed
Showing with 5 additions and 2 deletions.
  1. +5 −2 beautify-html.js
View
7 beautify-html.js
@@ -444,7 +444,11 @@ function style_html(html_source, options) {
multi_parser.current_mode = 'CONTENT';
break;
case 'TK_TAG_END':
- multi_parser.print_newline(true, multi_parser.output);
+ //Print new line only if the tag has no content and has child
+ if ((multi_parser.last_token === 'TK_CONTENT' && multi_parser.last_text === '')
+ && (multi_parser.output[multi_parser.output.length -1]
+ .indexOf(multi_parser.token_text.replace("</", "<").replace(">", " ")) !== 0))
+ multi_parser.print_newline(true, multi_parser.output);
multi_parser.print_token(multi_parser.token_text);
multi_parser.current_mode = 'CONTENT';
break;
@@ -455,7 +459,6 @@ function style_html(html_source, options) {
break;
case 'TK_CONTENT':
if (multi_parser.token_text !== '') {
- multi_parser.print_newline(false, multi_parser.output);
multi_parser.print_token(multi_parser.token_text);
}
multi_parser.current_mode = 'TAG';

0 comments on commit d152692

Please sign in to comment.
Something went wrong with that request. Please try again.