@@ -25,10 +25,64 @@ export const accessibleImageRender = (
2525  const  dom  =  imageRenderComputed . dom ; 
2626  const  imgSelector  =  dom . querySelector ( 'img' ) ; 
2727
28-   imgSelector ?. setAttribute ( 'alt' ,  '' ) ; 
29-   imgSelector ?. setAttribute ( 'role' ,  'presentation' ) ; 
30-   imgSelector ?. setAttribute ( 'aria-hidden' ,  'true' ) ; 
31-   imgSelector ?. setAttribute ( 'tabindex' ,  '-1' ) ; 
28+   // Set accessibility attributes for the image 
29+   if  ( block . props . caption )  { 
30+     // If there's a caption, make the image accessible with the caption as alt text 
31+     imgSelector ?. setAttribute ( 'alt' ,  block . props . caption ) ; 
32+     imgSelector ?. removeAttribute ( 'aria-hidden' ) ; 
33+     imgSelector ?. setAttribute ( 'tabindex' ,  '0' ) ; 
34+   }  else  { 
35+     // If no caption, keep image decorative 
36+     imgSelector ?. setAttribute ( 'alt' ,  '' ) ; 
37+     imgSelector ?. setAttribute ( 'role' ,  'presentation' ) ; 
38+     imgSelector ?. setAttribute ( 'aria-hidden' ,  'true' ) ; 
39+     imgSelector ?. setAttribute ( 'tabindex' ,  '-1' ) ; 
40+   } 
41+ 
42+   // Fix RGAA 1.9.1: Convert to figure/figcaption structure if caption exists 
43+   if  ( block . props . caption )  { 
44+     const  captionElement  =  dom . querySelector ( '.bn-file-caption' ) ; 
45+ 
46+     if  ( captionElement )  { 
47+       const  figureElement  =  document . createElement ( 'figure' ) ; 
48+ 
49+       // Copy all attributes from the original div 
50+       figureElement . className  =  dom . className ; 
51+       const  styleAttr  =  dom . getAttribute ( 'style' ) ; 
52+       if  ( styleAttr )  { 
53+         figureElement . setAttribute ( 'style' ,  styleAttr ) ; 
54+       } 
55+ 
56+       Array . from ( dom . children ) . forEach ( ( child )  =>  { 
57+         figureElement . appendChild ( child . cloneNode ( true ) ) ; 
58+       } ) ; 
59+ 
60+       // Replace the <p> caption with <figcaption> 
61+       const  figcaptionElement  =  document . createElement ( 'figcaption' ) ; 
62+       const  originalCaption  =  figureElement . querySelector ( '.bn-file-caption' ) ; 
63+       if  ( originalCaption )  { 
64+         figcaptionElement . className  =  originalCaption . className ; 
65+         figcaptionElement . textContent  =  originalCaption . textContent ; 
66+         originalCaption . parentNode ?. replaceChild ( 
67+           figcaptionElement , 
68+           originalCaption , 
69+         ) ; 
70+ 
71+         // Add explicit role and aria-label for better screen reader support 
72+         figureElement . setAttribute ( 'role' ,  'img' ) ; 
73+         figureElement . setAttribute ( 
74+           'aria-label' , 
75+           `Image: ${ figcaptionElement . textContent }  , 
76+         ) ; 
77+       } 
78+ 
79+       // Return the figure element as the new dom 
80+       return  { 
81+         ...imageRenderComputed , 
82+         dom : figureElement , 
83+       } ; 
84+     } 
85+   } 
3286
3387  return  { 
3488    ...imageRenderComputed , 
0 commit comments