@@ -227,6 +227,19 @@ function missingTag(tag) {
227227 ) ;
228228}
229229
230+ function addClass ( html , regex , newClass ) {
231+ return html . replace ( regex , function ( _ , tag , attributes ) {
232+ if ( / c l a s s = " ( [ ^ " ] * ) " / i. test ( attributes ) ) {
233+ attributes = attributes . replace ( / c l a s s = " ( [ ^ " ] * ) " / i, function ( _ , klass ) {
234+ return `class="${ klass } ${ newClass } "` ;
235+ } ) ;
236+ } else {
237+ attributes += ' class="' + newClass + '"' ;
238+ }
239+ return `<${ tag } ${ attributes } >` ;
240+ } ) ;
241+ }
242+
230243async function insertIntoIndexHTML (
231244 html ,
232245 htmlAttributes ,
@@ -254,9 +267,7 @@ async function insertIntoIndexHTML(
254267 } ) ;
255268
256269 if ( htmlClass ) {
257- html = html . replace ( / ( < h t m l .* ) c l a s s = " ( [ ^ " ] * ) " ( [ ^ > ] * ) / i, function ( _ , prefix , klass , suffix ) {
258- return prefix + `class="${ klass + ' ' + htmlClass . value } "` + suffix ;
259- } ) ;
270+ html = addClass ( html , / < ( h t m l ) ( .* ) > / i, htmlClass . value ) ;
260271 }
261272 if ( htmlAttributes ) {
262273 html = html . replace ( / < h t m l [ ^ > ] * / i, function ( match ) {
@@ -265,9 +276,7 @@ async function insertIntoIndexHTML(
265276 }
266277
267278 if ( bodyClass ) {
268- html = html . replace ( / ( < b o d y .* ) c l a s s = " ( [ ^ " ] * ) " ( [ ^ > ] * ) / i, function ( _ , prefix , klass , suffix ) {
269- return prefix + `class="${ klass + ' ' + bodyClass . value } "` + suffix ;
270- } ) ;
279+ html = addClass ( html , / < ( b o d y ) ( .* ) > / i, bodyClass . value ) ;
271280 }
272281 if ( bodyAttributes ) {
273282 html = html . replace ( / < b o d y [ ^ > ] * / i, function ( match ) {
0 commit comments