MCPcopy Index your code
hub / github.com/OpenCoworkAI/open-codesign / transformHtmlElementBlocks

Function transformHtmlElementBlocks

packages/shared/src/html-utils.ts:238–270  ·  view source on GitHub ↗
(
  html: string,
  tagName: string,
  transform: (input: { attrs: string; body: string; tag: string }) => string,
)

Source from the content-addressed store, hash-verified

236}
237
238export 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
272export function removeCspMetaTags(html: string): string {
273 const lower = html.toLowerCase();

Callers 5

hasTailwindScriptFunction · 0.90
hasTextBabelScriptFunction · 0.90
qualityCheckFunction · 0.90

Calls 4

tagOpenEndFunction · 0.85
findClosingTagStartFunction · 0.85
findClosingTagEndFunction · 0.85
findOpenTagFunction · 0.70

Tested by

no test coverage detected