@param {string} nodeType @param {string} content
(nodeType, content, options)
| 153 | @param {string} content |
| 154 | */ |
| 155 | function getFlowScalarLineContents(nodeType, content, options) { |
| 156 | const rawLineContents = content |
| 157 | .split("\n") |
| 158 | .map((lineContent, index, lineContents) => |
| 159 | index === 0 && index === lineContents.length - 1 |
| 160 | ? lineContent |
| 161 | : index !== 0 && index !== lineContents.length - 1 |
| 162 | ? lineContent.trim() |
| 163 | : index === 0 |
| 164 | ? lineContent.trimEnd() |
| 165 | : lineContent.trimStart(), |
| 166 | ); |
| 167 | |
| 168 | if (options.proseWrap === "preserve") { |
| 169 | return rawLineContents.map((lineContent) => |
| 170 | lineContent ? [lineContent] : [], |
| 171 | ); |
| 172 | } |
| 173 | |
| 174 | /** @type {string[][]} */ |
| 175 | const lines = []; |
| 176 | for (const [index, line] of rawLineContents.entries()) { |
| 177 | const words = splitWithSingleSpace(line); |
| 178 | |
| 179 | if ( |
| 180 | index > 0 && |
| 181 | rawLineContents[index - 1].length > 0 && |
| 182 | words.length > 0 && |
| 183 | !( |
| 184 | // trailing backslash in quoteDouble should be preserved |
| 185 | nodeType === "quoteDouble" && lines.at(-1).at(-1).endsWith("\\") |
| 186 | ) |
| 187 | ) { |
| 188 | lines[lines.length - 1] = [...lines.at(-1), ...words]; |
| 189 | } else { |
| 190 | lines.push(words); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | return options.proseWrap === "never" |
| 195 | ? lines.map((words) => [words.join(" ")]) |
| 196 | : lines; |
| 197 | } |
| 198 | |
| 199 | function getBlockValueLineContents( |
| 200 | node, |
no test coverage detected
searching dependent graphs…