MCPcopy Create free account
hub / github.com/bigskysoftware/_hyperscript / extractRegions

Function extractRegions

src/platform/node-hyperscript.js:180–214  ·  view source on GitHub ↗
(text, attrPattern, scriptPattern)

Source from the content-addressed store, hash-verified

178// ===== Region extraction (adapted from tools/lsp/src/regions.js) =====
179
180function extractRegions(text, attrPattern, scriptPattern) {
181 const regions = [];
182
183 // Attribute regions
184 attrPattern.lastIndex = 0;
185 let match;
186 while ((match = attrPattern.exec(text)) !== null) {
187 const quote = match[2];
188 const contentStart = match.index + match[0].length;
189 const contentEnd = findClosingQuote(text, contentStart, quote);
190 if (contentEnd > contentStart) {
191 regions.push({
192 source: text.substring(contentStart, contentEnd),
193 offset: contentStart,
194 type: 'attribute',
195 });
196 }
197 }
198
199 // Script block regions
200 scriptPattern.lastIndex = 0;
201 while ((match = scriptPattern.exec(text)) !== null) {
202 const contentStart = match.index + match[0].indexOf('>') + 1;
203 const source = match[1];
204 if (source.trim()) {
205 regions.push({
206 source,
207 offset: contentStart,
208 type: 'script',
209 });
210 }
211 }
212
213 return regions;
214}
215
216function findClosingQuote(text, start, quote) {
217 let i = start;

Callers 1

validateFileFunction · 0.70

Calls 1

findClosingQuoteFunction · 0.70

Tested by

no test coverage detected