(text, attrPattern, scriptPattern)
| 178 | // ===== Region extraction (adapted from tools/lsp/src/regions.js) ===== |
| 179 | |
| 180 | function 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 | |
| 216 | function findClosingQuote(text, start, quote) { |
| 217 | let i = start; |
no test coverage detected