(lines, startIndex, parentIndent, style)
| 80 | } |
| 81 | |
| 82 | function parseBlockScalar(lines, startIndex, parentIndent, style) { |
| 83 | const blockLines = []; |
| 84 | let index = startIndex; |
| 85 | |
| 86 | while (index < lines.length) { |
| 87 | const line = lines[index]; |
| 88 | const trimmed = line.trim(); |
| 89 | const currentIndent = countIndent(line); |
| 90 | |
| 91 | if (trimmed && currentIndent <= parentIndent) { |
| 92 | break; |
| 93 | } |
| 94 | |
| 95 | blockLines.push(line); |
| 96 | index += 1; |
| 97 | } |
| 98 | |
| 99 | const contentIndent = blockLines.reduce((minimumIndent, line) => { |
| 100 | const trimmed = line.trim(); |
| 101 | if (!trimmed) { |
| 102 | return minimumIndent; |
| 103 | } |
| 104 | const currentIndent = countIndent(line); |
| 105 | if (currentIndent <= parentIndent) { |
| 106 | return minimumIndent; |
| 107 | } |
| 108 | return minimumIndent === null ? currentIndent : Math.min(minimumIndent, currentIndent); |
| 109 | }, null); |
| 110 | |
| 111 | const normalizedLines = blockLines.map((line) => { |
| 112 | if (!line.trim()) { |
| 113 | return ""; |
| 114 | } |
| 115 | if (contentIndent === null) { |
| 116 | return line.trim(); |
| 117 | } |
| 118 | return line.slice(contentIndent); |
| 119 | }); |
| 120 | |
| 121 | return { |
| 122 | value: style === "|" ? normalizedLines.join("\n") : foldBlockScalarLines(normalizedLines), |
| 123 | nextIndex: index, |
| 124 | }; |
| 125 | } |
| 126 | |
| 127 | function parseBlock(lines, startIndex, indent) { |
| 128 | const firstIndex = nextMeaningfulIndex(lines, startIndex); |
no test coverage detected