MCPcopy
hub / github.com/garrytan/gstack / extractDescription

Function extractDescription

test/gen-skill-docs.test.ts:29–59  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

27}
28
29function extractDescription(content: string): string {
30 const fmEnd = content.indexOf('\n---', 4);
31 expect(fmEnd).toBeGreaterThan(0);
32 const frontmatter = content.slice(4, fmEnd);
33 const lines = frontmatter.split('\n');
34 let description = '';
35 let inDescription = false;
36 const descLines: string[] = [];
37
38 for (const line of lines) {
39 if (line.match(/^description:\s*\|?\s*$/)) {
40 inDescription = true;
41 continue;
42 }
43 if (line.match(/^description:\s*\S/)) {
44 return line.replace(/^description:\s*/, '').trim();
45 }
46 if (inDescription) {
47 if (line === '' || line.match(/^\s/)) {
48 descLines.push(line.replace(/^ /, ''));
49 } else {
50 break;
51 }
52 }
53 }
54
55 if (descLines.length > 0) {
56 description = descLines.join('\n').trim();
57 }
58 return description;
59}
60
61function extractMarkdownSection(content: string, heading: string): string {
62 const escaped = heading.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');

Callers 1

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected