File tree Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -127,7 +127,7 @@ export const usePDF = () => {
127
127
128
128
const image = ( entity : Entity ) => {
129
129
if ( entity . external ?. image ?. alignment === 'full' ) {
130
- if ( entity . raw . includes ( 'svg' ) ) {
130
+ if ( entity . external . image . name . includes ( 'svg' ) ) {
131
131
return {
132
132
svg : entity . raw ,
133
133
width :
@@ -161,7 +161,7 @@ export const usePDF = () => {
161
161
] ,
162
162
}
163
163
} else {
164
- if ( entity . raw . includes ( 'svg' ) ) {
164
+ if ( entity . external ?. image ?. name . includes ( 'svg' ) ) {
165
165
return {
166
166
svg : entity . raw ,
167
167
width : entity . external ?. image ?. size . width ,
Original file line number Diff line number Diff line change @@ -337,6 +337,12 @@ export const useRaw = () => {
337
337
338
338
const make = ( ) => {
339
339
const image = ( entity : Entity ) => {
340
+ if ( ! support ( ) . images ( entity . external ?. image ?. name as string ) ) {
341
+ return `<div class="flex wb-text text-xl items-end w-full justify-center py-5">
342
+ <svg id="unsupported-extension-image" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="h-7 w-7" preserveAspectRatio="xMidYMid meet" viewBox="0 0 20 20"><g stroke-width="1.5" fill="none"><path d="M12 8v4" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path><path d="M12 16.01l.01-.011" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path><path d="M9 3H4v3" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path><path d="M4 11v2" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path><path d="M20 11v2" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path><path d="M15 3h5v3" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path><path d="M9 21H4v-3" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path><path d="M15 21h5v-3" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path></g></svg>
343
+ </div>`
344
+ }
345
+
340
346
return `<div class="flex wb-text text-xl items-end w-full justify-center py-5">
341
347
<svg
342
348
xmlns="http://www.w3.org/2000/svg"
@@ -658,6 +664,19 @@ export const useRaw = () => {
658
664
} )
659
665
}
660
666
667
+ const support = ( ) => {
668
+ const images = ( file : string ) => {
669
+ return (
670
+ file . includes ( 'svg' ) ||
671
+ file . includes ( 'png' ) ||
672
+ file . includes ( 'jpeg' ) ||
673
+ file . includes ( 'jpg' )
674
+ )
675
+ }
676
+
677
+ return { images }
678
+ }
679
+
661
680
return {
662
681
html,
663
682
caret,
@@ -668,6 +687,7 @@ export const useRaw = () => {
668
687
style,
669
688
normalize,
670
689
copy,
690
+ support,
671
691
}
672
692
}
673
693
Original file line number Diff line number Diff line change @@ -387,4 +387,27 @@ describe('Raw v2 - Make', () => {
387
387
} )
388
388
) . toContain ( file_name )
389
389
} )
390
+
391
+ it ( 'should not create image because unsupported extension' , ( ) => {
392
+ const file_name = 'foo.bw'
393
+
394
+ expect (
395
+ make . image ( {
396
+ type : 'image' ,
397
+ raw : 'dsaKDSADaskASHDGYasdahbdasnASD...' ,
398
+ createdAt : format . actually ( ) ,
399
+ updatedAt : format . actually ( ) ,
400
+ external : {
401
+ image : {
402
+ name : file_name ,
403
+ size : {
404
+ width : 0 ,
405
+ height : 0 ,
406
+ } ,
407
+ alignment : 'full' ,
408
+ } ,
409
+ } ,
410
+ } )
411
+ ) . toContain ( 'id="unsupported-extension-image"' )
412
+ } )
390
413
} )
You can’t perform that action at this time.
0 commit comments