Commit 5aa075a 1 parent 440357b commit 5aa075a Copy full SHA for 5aa075a
File tree 2 files changed +30
-7
lines changed
2 files changed +30
-7
lines changed Original file line number Diff line number Diff line change 114
114
throw new Error (` Failed to import component: ${ error} ` );
115
115
}
116
116
},
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
+ */
117
122
parseTemplate (content ) {
118
123
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' )
120
138
if (template) {
121
139
codeBlocks .push ({
122
140
language: ' html' ,
123
- content: template[ 1 ]. trim () ,
141
+ content: template,
124
142
});
125
143
}
126
- const script = content .match (/ <script>([\s\S ] *? )<\/ script>/ );
144
+
145
+ const script = applyRegex (' script' )
127
146
if (script) {
128
147
codeBlocks .push ({
129
148
language: ' javascript' ,
130
- content: script[ 1 ]. trim () ,
149
+ content: script,
131
150
});
132
151
}
133
- const style = content .match (/ <style[\s\S ] *? >([\s\S ] *? )<\/ style>/ );
152
+
153
+ const style = applyRegex (' style' )
134
154
if (style) {
135
155
codeBlocks .push ({
136
156
language: ' scss' ,
137
- content: style[1 ]. trim () ,
157
+ content: style[1 ],
138
158
});
139
159
}
140
160
return codeBlocks;
Original file line number Diff line number Diff line change 83
83
},
84
84
"browserslist" : [
85
85
" extends browserslist-config-kolibri"
86
- ]
86
+ ],
87
+ "volta" : {
88
+ "node" : " 18.20.6"
89
+ }
87
90
}
You can’t perform that action at this time.
0 commit comments