From 6c4b5ea278dcf5bc144bfe47f0be5566127091fd Mon Sep 17 00:00:00 2001 From: Diogo Doreto Date: Tue, 5 Aug 2025 21:19:39 +0200 Subject: [PATCH] feat: use link description as alt attribute for image tags Fix https://github.com/wallyqs/org-ruby/issues/102 --- lib/org-ruby/html_output_buffer.rb | 19 +++++++------------ .../image-with-alt-description.html | 3 +++ .../image-with-alt-description.org | 5 +++++ 3 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 spec/html_examples/image-with-alt-description.html create mode 100644 spec/html_examples/image-with-alt-description.org diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb index 180bd80..fc14bc4 100644 --- a/lib/org-ruby/html_output_buffer.rb +++ b/lib/org-ruby/html_output_buffer.rb @@ -314,19 +314,14 @@ def inline_formatting(str) text.sub!(/\Afile(|\+emacs|\+sys):(?=[^\s]+\Z)/, "") end - # We don't add a description for images in links, because its - # empty value forces the image to be inlined. - defi ||= link unless link =~ @re_help.org_image_file_regexp - - if defi =~ @re_help.org_image_file_regexp - defi = quote_tags "\"#{defi}\"" - end - - if defi - link = @options[:link_abbrevs][link] if @options[:link_abbrevs].has_key? link - quote_tags("") + defi + quote_tags("") + if link =~ @re_help.org_image_file_regexp + quote_tags "\"#{defi" else - quote_tags "\"#{link}\"" + if defi =~ @re_help.org_image_file_regexp + defi = quote_tags "\"#{defi}\"" + end + link = @options[:link_abbrevs][link] if @options[:link_abbrevs].has_key? link + quote_tags("") + (defi || link) + quote_tags("") end end diff --git a/spec/html_examples/image-with-alt-description.html b/spec/html_examples/image-with-alt-description.html new file mode 100644 index 0000000..57baf72 --- /dev/null +++ b/spec/html_examples/image-with-alt-description.html @@ -0,0 +1,3 @@ +

Image with alt description

+

This image should use the description as the alt attribute:

+

A screenshot of our new UI

diff --git a/spec/html_examples/image-with-alt-description.org b/spec/html_examples/image-with-alt-description.org new file mode 100644 index 0000000..d453ab5 --- /dev/null +++ b/spec/html_examples/image-with-alt-description.org @@ -0,0 +1,5 @@ +Image with alt description + +This image should use the description as the alt attribute: + +[[file:screenshots/cool_screenshot.jpg][A screenshot of our new UI]]