From eab734b4572a27c8ee927baa575b6e38d3df1907 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sun, 27 Jan 2019 18:08:57 +0000 Subject: [PATCH] Match CommonMark's rendering a bit better --- src/Html/Renderables/Element.php | 22 +++++++++++----------- tests/data/deeply_nested_list.html | 18 ++++++++++++------ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/Html/Renderables/Element.php b/src/Html/Renderables/Element.php index 6ae205f..af08727 100644 --- a/src/Html/Renderables/Element.php +++ b/src/Html/Renderables/Element.php @@ -195,25 +195,25 @@ final class Element implements Renderable if ($this->Contents !== null) { $html .= '>'; - $First = \reset($this->Contents); - - if ( - $First instanceof Element - && ! \array_key_exists(\strtolower($First->name()), self::$TEXT_LEVEL_ELEMENTS) - ) { - $html .= "\n"; - } - if (! empty($this->Contents)) { foreach ($this->Contents as $C) { - $html .= $C->getHtml(); - if ( $C instanceof Element && ! \array_key_exists(\strtolower($C->name()), self::$TEXT_LEVEL_ELEMENTS) ) { $html .= "\n"; } + + $html .= $C->getHtml(); + } + + $Last = \end($this->Contents); + + if ( + $Last instanceof Element + && ! \array_key_exists(\strtolower($Last->name()), self::$TEXT_LEVEL_ELEMENTS) + ) { + $html .= "\n"; } } diff --git a/tests/data/deeply_nested_list.html b/tests/data/deeply_nested_list.html index 96efd22..7d7b258 100644 --- a/tests/data/deeply_nested_list.html +++ b/tests/data/deeply_nested_list.html @@ -1,6 +1,8 @@