( content: string, defaultDescription: string = 'Custom item', )
| 50 | * Uses the first non-empty line as the description, or falls back to a default |
| 51 | */ |
| 52 | export function extractDescriptionFromMarkdown( |
| 53 | content: string, |
| 54 | defaultDescription: string = 'Custom item', |
| 55 | ): string { |
| 56 | const lines = content.split('\n') |
| 57 | for (const line of lines) { |
| 58 | const trimmed = line.trim() |
| 59 | if (trimmed) { |
| 60 | // If it's a header, strip the header prefix |
| 61 | const headerMatch = trimmed.match(/^#+\s+(.+)$/) |
| 62 | const text = headerMatch?.[1] ?? trimmed |
| 63 | |
| 64 | // Return the text, limited to reasonable length |
| 65 | return text.length > 100 ? text.substring(0, 97) + '...' : text |
| 66 | } |
| 67 | } |
| 68 | return defaultDescription |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Parses tools from frontmatter, supporting both string and array formats |
no outgoing calls
no test coverage detected