MCPcopy Create free account
hub / github.com/adobe/react-spectrum / extractNameAndDescription

Function extractNameAndDescription

packages/dev/mcp/shared/src/parser.ts:25–66  ·  view source on GitHub ↗
(lines: string[])

Source from the content-addressed store, hash-verified

23}
24
25export function extractNameAndDescription(lines: string[]): {name: string; description?: string} {
26 let name = '';
27 let description: string | undefined = undefined;
28
29 let i = 0;
30 for (; i < lines.length; i++) {
31 const line = lines[i];
32 if (line.startsWith('# ')) {
33 name = line.replace(/^#\s+/, '').trim();
34 i++;
35 break;
36 }
37 }
38
39 let descLines: string[] = [];
40 let inCode = false;
41 for (; i < lines.length; i++) {
42 const line = lines[i];
43 if (/^```/.test(line.trim())) {
44 inCode = !inCode;
45 }
46 if (inCode) {
47 continue;
48 }
49 if (line.trim() === '') {
50 if (descLines.length > 0) {
51 break;
52 } else {
53 continue;
54 }
55 }
56 if (/^#{1,6}\s/.test(line) || /^</.test(line.trim())) {
57 continue;
58 }
59 descLines.push(line);
60 }
61 if (descLines.length > 0) {
62 description = descLines.join('\n').trim();
63 }
64
65 return {name, description};
66}

Callers 1

ensureParsedPageFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected