From 4efc95a33d8d3afd918359301b7dbf05016947b6 Mon Sep 17 00:00:00 2001 From: David Wessman Date: Thu, 10 Aug 2023 21:18:30 +0200 Subject: [PATCH] Handles newline after self-closing html node --- lib/syntax_tree/erb/nodes.rb | 2 +- test/html_test.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/syntax_tree/erb/nodes.rb b/lib/syntax_tree/erb/nodes.rb index 6f671ba..b276631 100644 --- a/lib/syntax_tree/erb/nodes.rb +++ b/lib/syntax_tree/erb/nodes.rb @@ -249,7 +249,7 @@ def deconstruct_keys(keys) # The HTML-closing tag is responsible for new lines after the node. def new_line - closing&.new_line + closing.nil? ? opening.new_line : closing&.new_line end def accept(visitor) diff --git a/test/html_test.rb b/test/html_test.rb index f5c351a..561bd99 100644 --- a/test/html_test.rb +++ b/test/html_test.rb @@ -148,6 +148,13 @@ def test_append_newlines assert_formatting("
What
", "
What
\n") end + def test_self_closing_with_blank_line + source = + "\n\nTest\n" + + assert_formatting(source, source) + end + def test_tag_with_leading_spaces source = "
What
" expected = "
What
\n"