(body: string)
| 221 | } |
| 222 | |
| 223 | function extractMarkdownFrontmatter(body: string): { |
| 224 | title?: string |
| 225 | description?: string |
| 226 | text: string |
| 227 | } { |
| 228 | const match = body.match(/^---\s*\r?\n([\s\S]*?)\r?\n---\s*\r?\n?/) |
| 229 | if (!match) { |
| 230 | return { text: normalizeText(decodeHtmlEntities(body)) } |
| 231 | } |
| 232 | |
| 233 | const frontmatter = match[1] |
| 234 | const getValue = (key: 'title' | 'description') => { |
| 235 | const valueMatch = frontmatter.match( |
| 236 | new RegExp(`^${key}:\\s*(?:"([^"]*)"|'([^']*)'|(.+))\\s*$`, 'm'), |
| 237 | ) |
| 238 | return normalizeText( |
| 239 | decodeHtmlEntities( |
| 240 | valueMatch?.[1] ?? valueMatch?.[2] ?? valueMatch?.[3] ?? '', |
| 241 | ), |
| 242 | ) |
| 243 | } |
| 244 | |
| 245 | return { |
| 246 | title: getValue('title') || undefined, |
| 247 | description: getValue('description') || undefined, |
| 248 | text: normalizeText(decodeHtmlEntities(body.slice(match[0].length))), |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | function isJsonContentType(contentType: string): boolean { |
| 253 | return ( |
no test coverage detected