File tree 4 files changed +105
-2
lines changed
4 files changed +105
-2
lines changed Original file line number Diff line number Diff line change @@ -182,8 +182,13 @@ module.exports = () => {
182
182
var w = width || '' ;
183
183
var opt = { ...opts } ;
184
184
var rule = this . get ( selectors , s , w , opt ) ;
185
- if ( rule ) return rule ;
186
- else {
185
+
186
+ // do not create rules that were found before
187
+ // unless this is an at-rule, for which multiple declarations
188
+ // make sense (e.g. multiple `@font-type`s)
189
+ if ( rule && rule . config && ! rule . config . atRuleType ) {
190
+ return rule ;
191
+ } else {
187
192
opt . state = s ;
188
193
opt . mediaText = w ;
189
194
opt . selectors = '' ;
Original file line number Diff line number Diff line change @@ -157,6 +157,27 @@ describe('GrapesJS', () => {
157
157
expect ( editor . getStyle ( ) . length ) . toEqual ( 2 ) ;
158
158
} ) ;
159
159
160
+ it ( 'Init editor from element with multiple font-face at-rules' , ( ) => {
161
+ config . fromElement = 1 ;
162
+ config . storageManager = { type : 0 } ;
163
+ fixture . innerHTML =
164
+ `
165
+ <style>
166
+ @font-face {
167
+ font-family: 'Glyphicons Halflings';
168
+ src: url(https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/fonts/glyphicons-halflings-regular.woff2) format('woff2');
169
+ }
170
+ @font-face {
171
+ font-family: 'Droid Sans';
172
+ src: url(https://fonts.gstatic.com/s/droidsans/v8/SlGVmQWMvZQIdix7AFxXkHNSbRYXags.woff2) format('woff2');
173
+ }
174
+ </style>` + htmlString ;
175
+ const editor = obj . init ( config ) ;
176
+ const css = editor . getCss ( ) ;
177
+ const styles = editor . getStyle ( ) ;
178
+ expect ( styles . length ) . toEqual ( 2 ) ;
179
+ } ) ;
180
+
160
181
it ( 'Set components as HTML' , ( ) => {
161
182
var editor = obj . init ( config ) ;
162
183
editor . setComponents ( htmlString ) ;
Original file line number Diff line number Diff line change @@ -277,6 +277,39 @@ module.exports = {
277
277
expect ( obj . parse ( str ) ) . toEqual ( result ) ;
278
278
} ) ;
279
279
280
+ it ( 'Parses multiple font-face at-rules' , ( ) => {
281
+ const str = `
282
+ @font-face {
283
+ font-family: "Open Sans";
284
+ }
285
+ @font-face {
286
+ font-family: 'Glyphicons Halflings';
287
+ src:url(https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/fonts/glyphicons-halflings-regular.eot)
288
+ }` ;
289
+ const result = [
290
+ {
291
+ selectors : [ ] ,
292
+ selectorsAdd : '' ,
293
+ style : { 'font-family' : '"Open Sans"' } ,
294
+ singleAtRule : 1 ,
295
+ atRuleType : 'font-face'
296
+ } ,
297
+ {
298
+ selectors : [ ] ,
299
+ selectorsAdd : '' ,
300
+ style : {
301
+ 'font-family' : "'Glyphicons Halflings'" ,
302
+ src :
303
+ 'url(https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/fonts/glyphicons-halflings-regular.eot)'
304
+ } ,
305
+ singleAtRule : 1 ,
306
+ atRuleType : 'font-face'
307
+ }
308
+ ] ;
309
+ const parsed = obj . parse ( str ) ;
310
+ expect ( parsed ) . toEqual ( result ) ;
311
+ } ) ;
312
+
280
313
it ( 'Parse ID rule' , ( ) => {
281
314
var str = `#test { color: red }` ;
282
315
var result = {
Original file line number Diff line number Diff line change @@ -372,6 +372,50 @@ module.exports = {
372
372
expect ( res . css ) . toEqual ( resCss ) ;
373
373
} ) ;
374
374
375
+ it ( 'Respect multiple font-faces contained in styles in html' , ( ) => {
376
+ const str = `
377
+ <style>
378
+ @font-face {
379
+ font-family: "Open Sans";
380
+ src:url(https://fonts.gstatic.com/s/droidsans/v8/SlGVmQWMvZQIdix7AFxXkHNSbRYXags.woff2)
381
+ }
382
+ @font-face {
383
+ font-family: 'Glyphicons Halflings';
384
+ src:url(https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/fonts/glyphicons-halflings-regular.eot)
385
+ }
386
+ </style>
387
+ <div>a div</div>
388
+ ` ;
389
+
390
+ const expected = [
391
+ {
392
+ selectors : [ ] ,
393
+ selectorsAdd : '' ,
394
+ style : {
395
+ 'font-family' : '"Open Sans"' ,
396
+ src :
397
+ 'url(https://fonts.gstatic.com/s/droidsans/v8/SlGVmQWMvZQIdix7AFxXkHNSbRYXags.woff2)'
398
+ } ,
399
+ singleAtRule : 1 ,
400
+ atRuleType : 'font-face'
401
+ } ,
402
+ {
403
+ selectors : [ ] ,
404
+ selectorsAdd : '' ,
405
+ style : {
406
+ 'font-family' : "'Glyphicons Halflings'" ,
407
+ src :
408
+ 'url(https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/fonts/glyphicons-halflings-regular.eot)'
409
+ } ,
410
+ singleAtRule : 1 ,
411
+ atRuleType : 'font-face'
412
+ }
413
+ ] ;
414
+
415
+ const res = obj . parse ( str , new ParserCss ( ) ) ;
416
+ expect ( res . css ) . toEqual ( expected ) ;
417
+ } ) ;
418
+
375
419
it ( 'Parse nested div with text and spaces' , ( ) => {
376
420
var str = '<div> <p>TestText</p> </div>' ;
377
421
var result = {
You can’t perform that action at this time.
0 commit comments