()
| 3281 | |
| 3282 | |
| 3283 | function prettyWriter() { |
| 3284 | var indentationLevel = 0; |
| 3285 | var indentation = " "; |
| 3286 | var stack = []; |
| 3287 | var start = true; |
| 3288 | var inText = false; |
| 3289 | |
| 3290 | var writer = simpleWriter(); |
| 3291 | |
| 3292 | function open(tagName, attributes) { |
| 3293 | if (indentedElements[tagName]) { |
| 3294 | indent(); |
| 3295 | } |
| 3296 | stack.push(tagName); |
| 3297 | writer.open(tagName, attributes); |
| 3298 | if (indentedElements[tagName]) { |
| 3299 | indentationLevel++; |
| 3300 | } |
| 3301 | start = false; |
| 3302 | } |
| 3303 | |
| 3304 | function close(tagName) { |
| 3305 | if (indentedElements[tagName]) { |
| 3306 | indentationLevel--; |
| 3307 | indent(); |
| 3308 | } |
| 3309 | stack.pop(); |
| 3310 | writer.close(tagName); |
| 3311 | } |
| 3312 | |
| 3313 | function text(value) { |
| 3314 | startText(); |
| 3315 | var text = isInPre() ? value : value.replace("\n", "\n" + indentation); |
| 3316 | writer.text(text); |
| 3317 | } |
| 3318 | |
| 3319 | function selfClosing(tagName, attributes) { |
| 3320 | indent(); |
| 3321 | writer.selfClosing(tagName, attributes); |
| 3322 | } |
| 3323 | |
| 3324 | function insideIndentedElement() { |
| 3325 | return stack.length === 0 || indentedElements[stack[stack.length - 1]]; |
| 3326 | } |
| 3327 | |
| 3328 | function startText() { |
| 3329 | if (!inText) { |
| 3330 | indent(); |
| 3331 | inText = true; |
| 3332 | } |
| 3333 | } |
| 3334 | |
| 3335 | function indent() { |
| 3336 | inText = false; |
| 3337 | if (!start && insideIndentedElement() && !isInPre()) { |
| 3338 | writer._append("\n"); |
| 3339 | for (var i = 0; i < indentationLevel; i++) { |
| 3340 | writer._append(indentation); |
no test coverage detected