Yes, in a sense.
My scenario is that I have the source HTML files imported to Jekyll and I generate a static site from them.
Now when the site is generated some image tags do not have alt text. So I need to use some sort of template/loop to add alt text to the images that don’t alt text.
However, I’m sorry, reading your original post again, it seems I’ve misunderstood your question… you want the alt value to be the same as the image’s src, not the page’s source, right?
You can probably achieve that by creating some liquid logic, maybe by assigning or capturing the the src and using it in the alt value. But I fail to see how to fully automate that…
Sorry again, and hopefully some one else shows up here. I’m curious about it as well.
The requirement is to have the alt text in the generated static html files so if we can achieve that using javascript then that is ok.
The object is to have the alt text in place before running Section 508/WCAG accessibility check utility.
The alt text will not be in the generated static files if you use JavaScript, as they will be added after the page has finished loading in a browser. I do not know if WCAG checkers allow JS to run.
How many images are we talkin’ about?
Are these images in content or in layouts?
Anyway, you’ll have to search for empty alt tags and copy the src attribute.
For content files, if you have Markdown, Jekyll will output the alt text correctly:
![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1")
generates
<img src="https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png" alt="alt text" title="Logo Title Text 1">
It’s very poor a11y to add the src attribute to alt tags, I can’t image a blind user using a screen reader and having to listen to the whole
image path instead of a useful information. You should try it and you’ll quickly understand why it’s a bad idea.
And some images do not need an alternative if the context provides explanation or if they are simply decoration.
This approach is going to be temporarily until I get the appropriate description for every image in the content.
I am currently using HTML not Markdown and the images are in the content not in layout.
Even though setting the alt tag value to the src value is a bad idea, do you know how to conduct the img tag search in the content? It is the ability to search and alter the img tag that I am really after.