(html: string)
| 19 | * of inputs that contain multiple sibling templates or other top-level content. |
| 20 | */ |
| 21 | export 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 | } |
no test coverage detected