MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / extractMarkdownFrontmatter

Function extractMarkdownFrontmatter

sdk/src/tools/read-url.ts:223–250  ·  view source on GitHub ↗
(body: string)

Source from the content-addressed store, hash-verified

221}
222
223function 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
252function isJsonContentType(contentType: string): boolean {
253 return (

Callers 1

extractTextByContentTypeFunction · 0.85

Calls 3

normalizeTextFunction · 0.85
decodeHtmlEntitiesFunction · 0.85
getValueFunction · 0.85

Tested by

no test coverage detected