From 6e0b22583f44452604136e12598aaf16c24dd3c4 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Sat, 18 Nov 2017 23:48:05 -0500 Subject: [PATCH] more pretty printing html (note this still changes content!) --- dom.d | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/dom.d b/dom.d index c62e760..f8f25ae 100644 --- a/dom.d +++ b/dom.d @@ -3177,18 +3177,19 @@ class Element { // for simple `texttext`, let's // just keep them on the same line - if(children.length == 1 && children[0].nodeType == NodeType.Text && children[0].nodeValue.strip.length) - s ~= children[0].toString(); - else - foreach(child; children) { - assert(child !is null); + if(allAreInlineHtml(children)) { + foreach(child; children) { + s ~= child.toString(); + } + } else { + foreach(child; children) { + assert(child !is null); - s ~= child.toPrettyString(insertComments, indentationLevel + 1, indentWith); - } + s ~= child.toPrettyString(insertComments, indentationLevel + 1, indentWith); + } - // see comment above - if(!(children.length == 1 && children[0].nodeType == NodeType.Text && children[0].nodeValue.strip.length)) s ~= toPrettyStringIndent(insertComments, indentationLevel, indentWith); + } s ~= "
$foo
$baz
`); } +/ + +bool allAreInlineHtml(const(Element)[] children) { + foreach(child; children) { + if(child.nodeType == NodeType.Text && child.nodeValue.strip.length) { + // cool + } else if(child.tagName.isInArray(inlineElements) && allAreInlineHtml(child.children)) { + // cool + } else { + // prolly block + return false; + } + } + return true; +} + /* Copyright: Adam D. Ruppe, 2010 - 2017 License: Boost License 1.0.