MCPcopy
hub / github.com/PatrickJS/awesome-cursorrules / extractSection

Function extractSection

scripts/check-awesome-list.mjs:115–124  ·  view source on GitHub ↗
(markdown, heading)

Source from the content-addressed store, hash-verified

113}
114
115function extractSection(markdown, heading) {
116 const pattern = new RegExp(`^##\\s+${escapeRegExp(heading)}\\s*$`, "m");
117 const match = markdown.match(pattern);
118 if (!match || match.index === undefined) return null;
119
120 const start = match.index + match[0].length;
121 const nextHeading = markdown.slice(start).match(/\n##\s+/);
122 const end = nextHeading?.index === undefined ? markdown.length : start + nextHeading.index;
123 return markdown.slice(start, end);
124}
125
126function escapeRegExp(value) {
127 return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");

Callers 2

checkReadmeStructureFunction · 0.85
checkContentsHierarchyFunction · 0.85

Calls 1

escapeRegExpFunction · 0.85

Tested by

no test coverage detected