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

Function extractMarkdownSection

test/gen-skill-docs.test.ts:61–72  ·  view source on GitHub ↗
(content: string, heading: string)

Source from the content-addressed store, hash-verified

59}
60
61function extractMarkdownSection(content: string, heading: string): string {
62 const escaped = heading.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
63 const startMatch = content.match(new RegExp(`^${escaped}.*$`, 'm'));
64 expect(startMatch?.index).toBeDefined();
65 const start = startMatch!.index!;
66 const afterHeading = start + startMatch![0].length;
67 const nextSection = content.slice(afterHeading).match(/\n## /);
68 const end = nextSection?.index === undefined
69 ? content.length
70 : afterHeading + nextSection.index;
71 return content.slice(start, end).trim();
72}
73
74function extractPreambleBeforeWorkflow(content: string, workflowMarkers: string[]): string {
75 const markerIndexes = workflowMarkers

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected