@@ -66,6 +66,27 @@ export class BasePlugin {
66
66
}
67
67
}
68
68
69
+ protected getAttributesString ( config : Config ) : string {
70
+ if ( config . attributes && typeof config . attributes === 'object' ) {
71
+ return (
72
+ ' ' +
73
+ Object . keys ( config . attributes )
74
+ . map ( ( key ) => `${ key } ="${ config . attributes ! [ key ] || '' } "` )
75
+ . join ( ' ' )
76
+ )
77
+ }
78
+
79
+ if ( config . attributes === undefined && config . attributes === null ) {
80
+ throw new Error (
81
+ `Please provide a key/value object if intending to use the attributes option, not ${
82
+ config . attributes
83
+ } `,
84
+ )
85
+ }
86
+
87
+ return ''
88
+ }
89
+
69
90
protected addStyle ( {
70
91
html,
71
92
htmlFileName,
@@ -75,25 +96,9 @@ export class BasePlugin {
75
96
htmlFileName : string
76
97
style : string
77
98
} ) {
78
- let attributesString = ''
79
-
80
- if ( this . config . attributes ) {
81
- if (
82
- typeof this . config . attributes !== 'object' &&
83
- this . config . attributes === null
84
- ) {
85
- throw new Error (
86
- `Please provide a key/value object if intending to use the attributes option` ,
87
- )
88
- }
89
-
90
- Object . keys ( this . config . attributes ) . map ( ( key ) => {
91
- const value = this . config . attributes [ key ] || ''
92
- attributesString += ` ${ key } ="${ value } "`
93
- } )
94
- }
95
-
96
- const styleString = `<style${ attributesString } >${ style } </style>`
99
+ const styleString = `<style${ this . getAttributesString (
100
+ this . config ,
101
+ ) } >${ style } </style>`
97
102
98
103
const replaceValues = [ styleString , this . replaceConfig . target ]
99
104
0 commit comments