(input: Array<string>, output: Array<string>)
| 78 | // * text has more than one adjacent line |
| 79 | // * markup does not close |
| 80 | const dedentMarkup = (input: Array<string>, output: Array<string>): boolean => { |
| 81 | let line = input[output.length]; |
| 82 | |
| 83 | if (!dedentStartTag(input, output)) { |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | if (input[output.length - 1].includes('/>')) { |
| 88 | return true; |
| 89 | } |
| 90 | |
| 91 | let isText = false; |
| 92 | const stack = [getIndentationLength(line)]; |
| 93 | |
| 94 | while (stack.length > 0 && output.length < input.length) { |
| 95 | line = input[output.length]; |
| 96 | |
| 97 | if (isFirstLineOfTag(line)) { |
| 98 | if (line.includes('</')) { |
| 99 | output.push(dedentLine(line)); |
| 100 | stack.pop(); |
| 101 | } else { |
| 102 | if (!dedentStartTag(input, output)) { |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | if (!input[output.length - 1].includes('/>')) { |
| 107 | stack.push(getIndentationLength(line)); |
| 108 | } |
| 109 | } |
| 110 | isText = false; |
| 111 | } else { |
| 112 | if (isText) { |
| 113 | return false; // because text has more than one adjacent line |
| 114 | } |
| 115 | |
| 116 | const indentationLengthOfTag = stack.at(-1)!; |
| 117 | output.push(line.slice(indentationLengthOfTag + 2)); |
| 118 | isText = true; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | return stack.length === 0; |
| 123 | }; |
| 124 | |
| 125 | // Return lines unindented by heuristic; |
| 126 | // otherwise return null because: |
no test coverage detected