@@ -18,23 +18,19 @@ def find_images_without_alt(file_path):
1818 inline_code_pattern = r"`[^`]*`"
1919 content_no_code = re .sub (inline_code_pattern , "" , content_no_code )
2020
21- # Pattern 1:  - markdown images without fig-alt
22- # Only flag images whose alt text is empty or whitespace
23- # Negative lookahead: (?!.*\{[^}]*fig-alt=) - ensures no fig-alt follows
24- md_pattern = r"(?<!\[)!\[(?:\s*)\]\([^)]+\)(?!.*?\{[^}]*fig-alt=)"
21+ md_pattern = r"(?<!\[)!\[(?:\s*)\]\([^)]+\)"
22+ attr_pattern = r"\{[^}]*(?:\balt=|\bfig-alt=)[^}]*\}"
2523
2624 for match in re .finditer (md_pattern , content_no_code ):
25+ end = match .end ()
26+ # Look at the next chunk of text after the image
27+ following = content_no_code [end :end + 200 ] # enough to include `{...}`
28+ if re .match (r"\s*" + attr_pattern , following ):
29+ # This image has alt/fig-alt in its attribute block; skip
30+ continue
2731 line_num = content [:match .start ()].count ("\n " ) + 1
2832 issues .append (("markdown" , line_num , match .group (0 )))
2933
30- # Pattern 2: <img> tags without alt attribute
31- # Matches <img...> that doesn't contain alt=
32- img_pattern = r"<img\s+(?![^>]*\balt=)[^>]*>"
33-
34- for match in re .finditer (img_pattern , content , re .IGNORECASE ):
35- line_num = content [:match .start ()].count ("\n " ) + 1
36- issues .append (("html" , line_num , match .group (0 )))
37-
3834 return issues
3935
4036
0 commit comments