MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / unwrapTemplate

Function unwrapTemplate

packages/engine/src/utils/htmlTemplate.ts:21–42  ·  view source on GitHub ↗
(html: string)

Source from the content-addressed store, hash-verified

19 * of inputs that contain multiple sibling templates or other top-level content.
20 */
21export function unwrapTemplate(html: string): string {
22 const lowered = html.toLowerCase();
23 if (!lowered.includes("<template") || !lowered.includes("</template>")) {
24 return html;
25 }
26
27 const { body } = parseHTMLContent(html);
28 if (!body) return html;
29
30 let container: Element = body;
31 const bodyWrapper = getSingleMeaningfulChild(container);
32 if (bodyWrapper?.tagName === "BODY") {
33 container = bodyWrapper;
34 }
35
36 const template = getSingleMeaningfulChild(container);
37 if (template?.tagName !== "TEMPLATE") {
38 return html;
39 }
40
41 return template.innerHTML ?? html;
42}

Callers 4

parseAudioElementsFunction · 0.85
parseVideoElementsFunction · 0.85
parseImageElementsFunction · 0.85

Calls 2

parseHTMLContentFunction · 0.90
getSingleMeaningfulChildFunction · 0.85

Tested by

no test coverage detected