Skip to content

Commit 5aa075a

Browse files
committed
fix bug with the parsing of nested template tags
1 parent 440357b commit 5aa075a

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

docs/common/DocsShow.vue

+26-6
Original file line numberDiff line numberDiff line change
@@ -114,27 +114,47 @@
114114
throw new Error(`Failed to import component: ${error}`);
115115
}
116116
},
117+
/*
118+
* Parses the content of the component file into separate code blocks for template, script, and style.
119+
* @param {string} content - The content of the component file
120+
* @returns {Array} An array of code blocks
121+
*/
117122
parseTemplate(content) {
118123
const codeBlocks = [];
119-
const template = content.match(/<template>([\s\S]*?)<\/template>/);
124+
125+
const applyRegex = (target) => {
126+
const pattern = new RegExp(`(<${target}(\\s[^>]*)?>)([\\w\\W]*)(<\\/${target}>)`, 'g');
127+
const parsed = pattern.exec(content);
128+
129+
if (!parsed) {
130+
return null;
131+
}
132+
133+
// Extract the content between the first opening and the last closing tags
134+
return parsed[3].trim();
135+
};
136+
137+
const template = applyRegex('template')
120138
if (template) {
121139
codeBlocks.push({
122140
language: 'html',
123-
content: template[1].trim(),
141+
content: template,
124142
});
125143
}
126-
const script = content.match(/<script>([\s\S]*?)<\/script>/);
144+
145+
const script = applyRegex('script')
127146
if (script) {
128147
codeBlocks.push({
129148
language: 'javascript',
130-
content: script[1].trim(),
149+
content: script,
131150
});
132151
}
133-
const style = content.match(/<style[\s\S]*?>([\s\S]*?)<\/style>/);
152+
153+
const style = applyRegex('style')
134154
if (style) {
135155
codeBlocks.push({
136156
language: 'scss',
137-
content: style[1].trim(),
157+
content: style[1],
138158
});
139159
}
140160
return codeBlocks;

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,8 @@
8383
},
8484
"browserslist": [
8585
"extends browserslist-config-kolibri"
86-
]
86+
],
87+
"volta": {
88+
"node": "18.20.6"
89+
}
8790
}

0 commit comments

Comments
 (0)