@@ -160,8 +160,16 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) {
160160 if (childrenAreLeaves(node) && fits(test)) {
161161 makeBox(ind, test)
162162 } else {
163- val (stg, len2) = startTag(node, pscope)
164- val etg = endTag(node)
163+ val ((stg, len2), etg) =
164+ if (node.child.isEmpty && minimizeEmpty) {
165+ // force the tag to be self-closing
166+ val firstAttribute = test.indexOf(' ' )
167+ val firstBreak = if (firstAttribute != - 1 ) firstAttribute else test.lastIndexOf('/' )
168+ ((test, firstBreak), " " )
169+ } else {
170+ (startTag(node, pscope), endTag(node))
171+ }
172+
165173 if (stg.length < width - cur) { // start tag fits
166174 makeBox(ind, stg)
167175 makeBreak()
@@ -180,10 +188,12 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) {
180188 makeBreak()
181189 }
182190 }*/
183- makeBox(ind, stg.substring(len2, stg.length))
184- makeBreak()
185- traverse(node.child.iterator, node.scope, ind + step)
186- makeBox(cur, etg)
191+ makeBox(ind, stg.substring(len2, stg.length).trim)
192+ if (etg.nonEmpty) {
193+ makeBreak()
194+ traverse(node.child.iterator, node.scope, ind + step)
195+ makeBox(cur, etg)
196+ }
187197 makeBreak()
188198 } else { // give up
189199 makeBox(ind, test)
0 commit comments