( html: string, tags: HtmlTagDescriptor[], prepend = false, )
| 1524 | const doctypePrependInjectRE = /<!doctype html>/i |
| 1525 | |
| 1526 | function injectToHead( |
| 1527 | html: string, |
| 1528 | tags: HtmlTagDescriptor[], |
| 1529 | prepend = false, |
| 1530 | ) { |
| 1531 | if (tags.length === 0) return html |
| 1532 | |
| 1533 | if (prepend) { |
| 1534 | // inject as the first element of head |
| 1535 | if (headPrependInjectRE.test(html)) { |
| 1536 | return html.replace( |
| 1537 | headPrependInjectRE, |
| 1538 | (match, p1) => `${match}\n${serializeTags(tags, incrementIndent(p1))}`, |
| 1539 | ) |
| 1540 | } |
| 1541 | } else { |
| 1542 | // inject before head close |
| 1543 | if (headInjectRE.test(html)) { |
| 1544 | // respect indentation of head tag |
| 1545 | return html.replace( |
| 1546 | headInjectRE, |
| 1547 | (match, p1) => `${serializeTags(tags, incrementIndent(p1))}${match}`, |
| 1548 | ) |
| 1549 | } |
| 1550 | // try to inject before the body tag |
| 1551 | if (bodyPrependInjectRE.test(html)) { |
| 1552 | return html.replace( |
| 1553 | bodyPrependInjectRE, |
| 1554 | (match, p1) => `${serializeTags(tags, p1)}\n${match}`, |
| 1555 | ) |
| 1556 | } |
| 1557 | } |
| 1558 | // if no head tag is present, we prepend the tag for both prepend and append |
| 1559 | return prependInjectFallback(html, tags) |
| 1560 | } |
| 1561 | |
| 1562 | function injectToBody( |
| 1563 | html: string, |
no test coverage detected