From 333e1ebef8643e2866d64b1651d65976eaca71e4 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Fri, 3 Dec 2021 10:59:03 -0500 Subject: [PATCH] a lil more pretty string tweaking for empty elements --- dom.d | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dom.d b/dom.d index 2ad083b..c28fd46 100644 --- a/dom.d +++ b/dom.d @@ -3520,7 +3520,7 @@ class Element : DomParent { // for simple `texttext`, let's // just keep them on the same line - if(tagName.isInArray(inlineElements) || allAreInlineHtml(children, inlineElements)) { + if(isEmpty || tagName.isInArray(inlineElements) || allAreInlineHtml(children, inlineElements)) { foreach(child; children) { s ~= child.toString();//toPrettyString(false, 0, null); } @@ -7827,7 +7827,7 @@ bool allAreInlineHtml(const(Element)[] children, const string[] inlineElements) foreach(child; children) { if(child.nodeType == NodeType.Text && child.nodeValue.strip.length) { // cool - } else if(child.tagName.isInArray(inlineElements) && allAreInlineHtml(child.children, inlineElements)) { + } else if(child.isEmpty || child.tagName.isInArray(inlineElements) && allAreInlineHtml(child.children, inlineElements)) { // cool } else { // prolly block @@ -8003,6 +8003,7 @@ unittest { // despite these being in a test, I might change these anyway! assert(Element.make("a").toPrettyString == ""); assert(Element.make("a", "").toPrettyString(false, 0, " ") == ""); + assert(Element.make("a", " ").toPrettyString(false, 0, " ") == " ");//, Element.make("a", " ").toPrettyString(false, 0, " ")); assert(Element.make("a", "b").toPrettyString == "b"); assert(Element.make("a", "b").toPrettyString(false, 0, "") == "b");