@@ -33,20 +33,8 @@ export const accessibleImageRender = (
3333 imgSelector ?. setAttribute ( 'alt' , block . props . caption ) ;
3434 imgSelector ?. removeAttribute ( 'aria-hidden' ) ;
3535 imgSelector ?. setAttribute ( 'tabindex' , '0' ) ;
36- } ;
3736
38- const accessibleImage = ( ) => {
39- imgSelector ?. setAttribute ( 'alt' , '' ) ;
40- imgSelector ?. setAttribute ( 'role' , 'presentation' ) ;
41- imgSelector ?. setAttribute ( 'aria-hidden' , 'true' ) ;
42- imgSelector ?. setAttribute ( 'tabindex' , '-1' ) ;
43- } ;
44-
45- // Set accessibility attributes for the image
46- withCaption ? accessibleImageWithCaption ( ) : accessibleImage ( ) ;
47-
48- // Fix RGAA 1.9.1: Convert to figure/figcaption structure if caption exists
49- if ( block . props . caption ) {
37+ // Fix RGAA 1.9.1: Convert to figure/figcaption structure if caption exists
5038 const captionElement = dom . querySelector ( '.bn-file-caption' ) ;
5139
5240 if ( captionElement ) {
@@ -89,6 +77,21 @@ export const accessibleImageRender = (
8977 dom : figureElement ,
9078 } ;
9179 }
80+ } ;
81+
82+ const accessibleImage = ( ) => {
83+ imgSelector ?. setAttribute ( 'alt' , '' ) ;
84+ imgSelector ?. setAttribute ( 'role' , 'presentation' ) ;
85+ imgSelector ?. setAttribute ( 'aria-hidden' , 'true' ) ;
86+ imgSelector ?. setAttribute ( 'tabindex' , '-1' ) ;
87+ } ;
88+
89+ // Set accessibility attributes for the image
90+ const result = withCaption ? accessibleImageWithCaption ( ) : accessibleImage ( ) ;
91+
92+ // Return the result if accessibleImageWithCaption created a figure, otherwise return original
93+ if ( result ) {
94+ return result ;
9295 }
9396
9497 return {
0 commit comments