(
html: string,
tagName: string,
transform: (input: { attrs: string; body: string; tag: string }) => string,
)
| 236 | } |
| 237 | |
| 238 | export function transformHtmlElementBlocks( |
| 239 | html: string, |
| 240 | tagName: string, |
| 241 | transform: (input: { attrs: string; body: string; tag: string }) => string, |
| 242 | ): string { |
| 243 | const tag = tagName.toLowerCase(); |
| 244 | const lower = html.toLowerCase(); |
| 245 | let out = ''; |
| 246 | let cursor = 0; |
| 247 | while (cursor < html.length) { |
| 248 | const open = findOpenTag(lower, tag, cursor); |
| 249 | if (open < 0) { |
| 250 | out += html.slice(cursor); |
| 251 | break; |
| 252 | } |
| 253 | const openEnd = tagOpenEnd(html, open); |
| 254 | const closeStart = findClosingTagStart(lower, tag, openEnd); |
| 255 | const closeEnd = closeStart < 0 ? -1 : findClosingTagEnd(lower, tag, openEnd); |
| 256 | if (closeStart < 0 || closeEnd < 0) { |
| 257 | out += html.slice(cursor, openEnd); |
| 258 | cursor = openEnd; |
| 259 | continue; |
| 260 | } |
| 261 | out += html.slice(cursor, open); |
| 262 | out += transform({ |
| 263 | attrs: html.slice(open + tag.length + 1, openEnd - 1), |
| 264 | body: html.slice(openEnd, closeStart), |
| 265 | tag: html.slice(open, closeEnd), |
| 266 | }); |
| 267 | cursor = closeEnd; |
| 268 | } |
| 269 | return out; |
| 270 | } |
| 271 | |
| 272 | export function removeCspMetaTags(html: string): string { |
| 273 | const lower = html.toLowerCase(); |
no test coverage detected