MCPcopy Index your code
hub / github.com/adobe/react-spectrum / parseSectionsFromMarkdown

Function parseSectionsFromMarkdown

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

Source from the content-addressed store, hash-verified

1import type {SectionInfo} from './types.js';
2
3export function parseSectionsFromMarkdown(lines: string[]): SectionInfo[] {
4 const sections: SectionInfo[] = [];
5 let inCode = false;
6 for (let idx = 0; idx < lines.length; idx++) {
7 const line = lines[idx];
8 if (/^```/.test(line.trim())) {
9 inCode = !inCode;
10 }
11 if (inCode) {
12 continue;
13 }
14 if (line.startsWith('## ')) {
15 const name = line.replace(/^##\s+/, '').trim();
16 sections.push({name, startLine: idx, endLine: lines.length});
17 }
18 }
19 for (let s = 0; s < sections.length - 1; s++) {
20 sections[s].endLine = sections[s + 1].startLine;
21 }
22 return sections;
23}
24
25export function extractNameAndDescription(lines: string[]): {name: string; description?: string} {
26 let name = '';

Callers 2

ensureParsedPageFunction · 0.85
registerLibraryDocsToolsFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected