@@ -85,6 +85,10 @@ const isTextNodeAValidWord = (child: ChildNode) => {
8585 return trimmedWord && ( trimmedWord . match ( / \w / ) || trimmedWord . length > 3 ) ; // Regex matches any character, number, or _
8686} ;
8787
88+ const isImageElement = ( el : HTMLElement ) => {
89+ return el . tagName . toLowerCase ( ) === "img" ;
90+ } ;
91+
8892const inputs = [ "a" , "button" , "textarea" , "select" , "details" , "label" ] ;
8993const isInteractable = ( el : HTMLElement ) => {
9094 // If it is a label but has an input child that it is a label for, say not interactable
@@ -233,6 +237,8 @@ function create_tagged_span(idNum: number, el: HTMLElement) {
233237 if ( isTextInsertable ( el ) ) idStr = `[#${ idNum } ]` ;
234238 else if ( el . tagName . toLowerCase ( ) == "a" ) idStr = `[@${ idNum } ]` ;
235239 else idStr = `[$${ idNum } ]` ;
240+ } else if ( isImageElement ( el ) ) {
241+ idStr = `[%${ idNum } ]` ;
236242 } else {
237243 idStr = `[${ idNum } ]` ;
238244 }
@@ -343,11 +349,11 @@ function getElementsToTag(
343349 const elementsToTag : HTMLElement [ ] = [ ] ;
344350
345351 for ( let el of allElements ) {
346- if ( isTextLess ( el ) || ! elIsVisible ( el ) ) {
352+ if ( ( isTextLess ( el ) && ! isImageElement ( el ) ) || ! elIsVisible ( el ) ) {
347353 continue ;
348354 }
349355
350- if ( isInteractable ( el ) ) {
356+ if ( isInteractable ( el ) || isImageElement ( el ) ) {
351357 elementsToTag . push ( el ) ;
352358 } else if ( tagLeafTexts ) {
353359 // Append the parent tag as it may have multiple individual child nodes with text
@@ -480,6 +486,14 @@ function insertTags(
480486 absolutelyPositionTagIfMisaligned ( idSpan , insertionElement ) ;
481487 }
482488 idNum ++ ;
489+ } else if ( isImageElement ( el ) ) {
490+ // Handle image elements
491+ const idSpan = create_tagged_span ( idNum , el ) ;
492+ if ( el . parentElement ) {
493+ el . parentElement . insertBefore ( idSpan , el ) ;
494+ absolutelyPositionTagIfMisaligned ( idSpan , el ) ;
495+ }
496+ idNum ++ ;
483497 } else if ( tagLeafTexts ) {
484498 trimTextNodeStart ( el ) ;
485499 const validTextNodes = Array . from ( el . childNodes ) . filter (
0 commit comments