@@ -160,8 +160,16 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) {
160
160
if (childrenAreLeaves(node) && fits(test)) {
161
161
makeBox(ind, test)
162
162
} 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
+
165
173
if (stg.length < width - cur) { // start tag fits
166
174
makeBox(ind, stg)
167
175
makeBreak()
@@ -180,10 +188,12 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) {
180
188
makeBreak()
181
189
}
182
190
}*/
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
+ }
187
197
makeBreak()
188
198
} else { // give up
189
199
makeBox(ind, test)
0 commit comments