From d8b40df35245722dda6a3067bc7ef0de34ea85ee Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Fri, 17 Nov 2017 13:09:07 -0500 Subject: [PATCH] better html pretty-printer --- dom.d | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/dom.d b/dom.d index cc33ff5..fbc3e18 100644 --- a/dom.d +++ b/dom.d @@ -3127,7 +3127,7 @@ class Element { // for simple `texttext`, let's // just keep them on the same line - if(children.length == 1 && children[0].nodeType == NodeType.Text) + if(children.length == 1 && children[0].nodeType == NodeType.Text && children[0].nodeValue.strip.length) s ~= children[0].toString(); else foreach(child; children) { @@ -3137,7 +3137,7 @@ class Element { } // see comment above - if(!(children.length == 1 && children[0].nodeType == NodeType.Text)) + if(!(children.length == 1 && children[0].nodeType == NodeType.Text && children[0].nodeValue.strip.length)) s ~= toPrettyStringIndent(insertComments, indentationLevel); s ~= " 0; + foreach(char c; contents) { + if(c == ' ' || c == '\n' || c == '\r' || c == '\t') { + if(!lastWasWhitespace) + n ~= ' '; + lastWasWhitespace = true; + } else { + n ~= c; + lastWasWhitespace = false; + } + } + + contents = n; + } + auto e = htmlEntitiesEncode(contents); import std.algorithm.iteration : splitter; bool first = true;