From 947566fbf3d22eed1cc95576ce956955efd34395 Mon Sep 17 00:00:00 2001 From: Ze Yu Date: Sun, 19 Jul 2020 14:18:10 +0800 Subject: [PATCH] Add newline for block end tag with multiline child --- index.html | 3 ++- js/src/html/beautifier.js | 13 ++++++++---- js/test/generated/beautify-html-tests.js | 15 ++++++++++++++ test/data/html/tests.js | 25 ++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index dd5c15f63..c76332139 100644 --- a/index.html +++ b/index.html @@ -206,7 +206,8 @@

Browser extensions and other uses

  • A bookmarklet - (drag it to your bookmarks) by Ichiro Hiroshi to see all scripts used on the page,
  • + (drag it to your bookmarks) by Ichiro Hiroshi to see all scripts used on the page, +
  • Chrome, in case the built-in CSS and javascript formatting isn't enough for you:
    Quick source viewer by Tomi Mickelsson (github, blog),
    diff --git a/js/src/html/beautifier.js b/js/src/html/beautifier.js index 15cba62be..7c222bf8b 100644 --- a/js/src/html/beautifier.js +++ b/js/src/html/beautifier.js @@ -734,12 +734,17 @@ Beautifier.prototype._set_tag_position = function(printer, raw_token, parser_tok } } - if (!parser_token.is_inline_element && last_token.type !== 'TK_CONTENT') { - if (parser_token.parent) { - parser_token.parent.multiline_content = true; - } + var do_set_parent_multiline; + if (parser_token.is_inline_element) { + do_set_parent_multiline = raw_token.newlines && parser_token.parent && !parser_token.parent.is_inline_element; + } else if (last_token.type !== 'TK_CONTENT') { + do_set_parent_multiline = parser_token.parent; printer.print_newline(false); } + + if (do_set_parent_multiline) { + parser_token.parent.multiline_content = true; + } } }; diff --git a/js/test/generated/beautify-html-tests.js b/js/test/generated/beautify-html-tests.js index bb461d9cd..0984121d5 100644 --- a/js/test/generated/beautify-html-tests.js +++ b/js/test/generated/beautify-html-tests.js @@ -172,6 +172,21 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be '\n' + ' \n' + ''); + test_fragment( + '
    \n' + + '\n' + + '
    ', + // -- output -- + '
    \n' + + ' \n' + + ' \n' + + '
    '); + test_fragment( + '', + // -- output -- + ''); //============================================================ diff --git a/test/data/html/tests.js b/test/data/html/tests.js index bfe43a95a..b1e0dcee9 100644 --- a/test/data/html/tests.js +++ b/test/data/html/tests.js @@ -70,6 +70,31 @@ exports.test_data = { ' ', '' ] + }, { + // Issue #1365 -- Inline tags with newlines should break block parent ending tags into another line + fragment: true, + input: [ + '
    ', + '', + '
    ' + ], + output: [ + '
    ', + ' ', + ' ', + '
    ' + ] + }, { + // Issue #1365 -- Inline tags with newlines should not break inline parent ending tags into another line + fragment: true, + input: [ + '' + ], + output: [ + '' + ] }] }, { name: "End With Newline",