Skip to content

Commit 9534024

Browse files
committed
🐛 fixed bug where unclosed <include> tags broke parsing
1 parent c2f23ab commit 9534024

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ function viteHTMLIncludes(options = {}) {
8282
});
8383
}
8484

85+
function ensureClosedIncludeTags(html) {
86+
// This regex finds <include> tags and ensures they are self-closing or properly closed
87+
const regex = /<include(.*?)>(?!(<\/include>))/g;
88+
return html.replace(regex, (match, attributes) => {
89+
// Check if it's already self-closing
90+
if (attributes.trim().endsWith('/')) {
91+
return match; // No change required
92+
} else {
93+
// Convert to self-closing tag for simplicity
94+
return `<include${attributes.trimEnd()} />`;
95+
}
96+
});
97+
}
98+
8599
function processTemplate(fragment, locals) {
86100
processConditionals(fragment, locals);
87101
processSwitchCases(fragment, locals);
@@ -96,6 +110,9 @@ function viteHTMLIncludes(options = {}) {
96110
config = resolvedConfig;
97111
},
98112
transformIndexHtml(html) {
113+
// Preprocess HTML to ensure <include> tags are closed
114+
html = ensureClosedIncludeTags(html);
115+
99116
const root = parse(html);
100117
root.querySelectorAll('include').forEach(node => {
101118
const src = node.getAttribute('src');

0 commit comments

Comments
 (0)