MCPcopy
hub / github.com/google-labs-code/design.md / extractSectionsFromContent

Function extractSectionsFromContent

packages/cli/src/linter/lint.ts:117–150  ·  view source on GitHub ↗

* Extract document sections from raw markdown content by finding H2 headings. * Used as a fallback when the parser cannot extract YAML.

(content: string)

Source from the content-addressed store, hash-verified

115 * Used as a fallback when the parser cannot extract YAML.
116 */
117function extractSectionsFromContent(content: string): Array<{ heading: string; content: string }> {
118 const lines = content.split('\n');
119 const sections: Array<{ heading: string; content: string }> = [];
120 const headingPattern = /^## (.+)$/;
121
122 let currentStart = 0;
123 let currentHeading = '';
124
125 for (let i = 0; i < lines.length; i++) {
126 const line = lines[i];
127 if (!line) continue;
128
129 const match = headingPattern.exec(line);
130 if (match) {
131 // Push previous section
132 if (i > 0) {
133 sections.push({
134 heading: currentHeading,
135 content: lines.slice(currentStart, i).join('\n'),
136 });
137 }
138 currentHeading = match[1] ?? '';
139 currentStart = i;
140 }
141 }
142
143 // Push final section
144 sections.push({
145 heading: currentHeading,
146 content: lines.slice(currentStart).join('\n'),
147 });
148
149 return sections;
150}

Callers 1

lintFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…