@@ -127,12 +127,16 @@ module.exports = function markdownToVueLoader(source, map) {
127
127
switch ( language ) {
128
128
case 'vue' : {
129
129
const $$ = cheerio . load ( $code . text ( ) , cheerioLoadOptions ) ;
130
+ const $body = $$ ( 'body' ) ;
130
131
const $style = $$ ( 'style' ) ;
131
132
132
133
component = $$ ( 'script' ) . html ( ) || 'export default {};' ;
133
134
scoped = $style . attr ( 'scoped' ) ;
134
135
style = $style . html ( ) ;
135
- $$ ( 'template' ) . each ( ( i , element ) => {
136
+
137
+ // Move <template> from <head> to <body>
138
+ $body . append ( $$ ( 'head > template' ) ) ;
139
+ $body . children ( 'template' ) . each ( ( i , element ) => {
136
140
template += $ ( element ) . html ( ) ;
137
141
} ) ;
138
142
break ;
@@ -151,8 +155,8 @@ module.exports = function markdownToVueLoader(source, map) {
151
155
$style . remove ( ) ;
152
156
153
157
// Move <template> from <head> to <body>
154
- $body . append ( $$ ( 'head template' ) ) ;
155
- $body . find ( 'template' ) . each ( ( i , element ) => {
158
+ $body . append ( $$ ( 'head > template' ) ) ;
159
+ $body . children ( 'template' ) . each ( ( i , element ) => {
156
160
const $element = $ ( element ) ;
157
161
158
162
$element . replaceWith ( $element . html ( ) ) ;
@@ -241,15 +245,15 @@ module.exports = function markdownToVueLoader(source, map) {
241
245
const $$ = cheerio . load ( '<template></template>' ) ;
242
246
const $body = $$ ( 'body' ) ;
243
247
244
- $body . append ( $$ ( 'head template' ) ) ;
245
-
246
248
$ ( 'style' ) . each ( ( index , style ) => {
247
249
const $style = $ ( style ) ;
248
250
249
251
$body . append ( $style ) ;
250
252
} ) ;
251
253
252
- $$ ( 'template' ) . html ( `<div><div class="${ options . componentNamespace } -${ normalizedResourceName } ">${ $ ( 'body' ) . html ( ) } </div></div>` ) ;
254
+ // Move <template> from <head> to <body>
255
+ $body . append ( $$ ( 'head > template' ) ) ;
256
+ $body . children ( 'template' ) . html ( `<div><div class="${ options . componentNamespace } -${ normalizedResourceName } ">${ $ ( 'body' ) . html ( ) } </div></div>` ) ;
253
257
254
258
if ( options . exportSource || components . length > 0 ) {
255
259
$body . append ( `<script>
0 commit comments