niklasfasching / go-org

Org mode parser with html & pretty printed org rendering. also shitty static site generator.
https://niklasfasching.github.io/go-org/
MIT License
343 stars 48 forks source link

Image alt text is assigned to the image link rather than to the image itself #108

Open zerotyr opened 5 months ago

zerotyr commented 5 months ago

I'm not sure where this issue actually lies (hugo vs. go-org). If this is the wrong repo, let me know.

I'm currently using hugo and org-mode to write blog posts. Note that I'm not using ox-hugo, but rather setting defaultMarkdownHandler = 'org' in hugo.toml. An issue I've run into is trying to find the correct way to provide alt text on images.

After a bit of experimentation, I figured out that the seemingly correct way to provide alt text for images was to supply the attribute alt to ATTR_HTML. However, the resulting HTML seems a bit odd to me. That said, I don't know how much this matters practice.

In the screenshot below, you'll see that the alt text is assigned to the link itself rather than the image, and the image is assigned the alt text of the file name provided in the org link's description.

* inline image with alt text
#+ATTR_HTML: :alt black mage rubbernecking bunny girl
[[file:./ffxiv-rubbernecking.png][file:./ffxiv-rubbernecking.png]]
<a href="./ffxiv-rubbernecking.png" alt="black mage rubbernecking bunny girl">
  <img src="./ffxiv-rubbernecking.png" alt="./ffxiv-rubbernecking.png">
</a>

Image

When performing an export on the same file using org-html-export-as-html, the alt text is assigned to both the link description and to the image itself as shown by the HTML generated by the export:

<a href="./ffxiv-rubbernecking.png" alt="black mage rubbernecking bunny girl">
  <img src="./ffxiv-rubbernecking.png" alt="black mage rubbernecking bunny girl"/>
</a>

When using alt text with an image without a description, it works as expected. However, this means my image is no longer clickable, so if the image was larger than the page, it wouldn't be possible to click on the image to see the larger version.

#+attr_html: :alt black mage rubbernecking bunny girl
[[file:./ffxiv-rubbernecking.png]]
<img src="./ffxiv-rubbernecking.png" alt="black mage rubbernecking bunny girl" title="./ffxiv-rubbernecking.png">

For me, the expected behavior is that the the alt text is assigned the same way when using org-html-export when using the org syntax in the first example provided, though I don't know if what org-export is doing is actually correct either from an accessibility standpoint.

If any more information is needed, let me know.

niklasfasching commented 3 months ago

Thx for the great report and sorry for the late reply. Totally makes sense, it's just a special case; we handle something similar for paragraphs that contain nothing but a link and set the attributes on the link rather than the containing paragraph (code). I'll get around to this eventually, but currently too much other stuff to work on.

zerotyr commented 3 months ago

no worries. thanks for looking into it. i may look into it myself to see if i can get it to work, though i'll need to teach myself go first