(frontmatter: string, field: string)
| 156 | } |
| 157 | |
| 158 | function readFrontmatterField(frontmatter: string, field: string): string | null { |
| 159 | const lines = frontmatter.split(/\r?\n/); |
| 160 | |
| 161 | for (let index = 0; index < lines.length; index += 1) { |
| 162 | const match = lines[index].match(/^([A-Za-z0-9_-]+):(?:\s*(.*))?$/); |
| 163 | if (!match || match[1] !== field) { |
| 164 | continue; |
| 165 | } |
| 166 | |
| 167 | const rawValue = (match[2] ?? "").trim(); |
| 168 | if (isBlockScalar(rawValue)) { |
| 169 | const [value] = readBlockScalar(lines, index + 1, rawValue); |
| 170 | return value; |
| 171 | } |
| 172 | |
| 173 | if (rawValue === "") { |
| 174 | const [value] = readIndentedScalar(lines, index + 1); |
| 175 | return value; |
| 176 | } |
| 177 | |
| 178 | return stripWrappingQuotes(rawValue); |
| 179 | } |
| 180 | |
| 181 | return null; |
| 182 | } |
| 183 | |
| 184 | function isBlockScalar(value: string): boolean { |
| 185 | return /^[>|][0-9+-]*$/.test(value); |
no test coverage detected