Skip to content

Commit d888afa

Browse files
authored
Merge pull request #366 from alphagov/stop-images-with-no-alt-being-wrapped-in-links
Only wrap images with alt text in hyperlinks
2 parents 64d0492 + 9ebbd21 commit d888afa

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ You need to
1515
- Use hidden attribute to show/hide expiry notices instead of just CSS
1616
- Only use dialog role for table of contents when it behaves like one (accessibility fix)
1717
- Prevent interactive elements being obscured by sticky table of contents header
18+
- Only wrap images with alt text in hyperlinks
1819

1920
## 3.5.0
2021

lib/govuk_tech_docs/tech_docs_html_renderer.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ def header(text, level)
1919
%(<h#{level} id="#{anchor}">#{text}</h#{level}>\n)
2020
end
2121

22-
def image(link, *args)
23-
%(<a href="#{link}" rel="noopener noreferrer">#{super}</a>)
22+
def image(link, title, alt_text)
23+
if alt_text && !alt_text.strip.empty?
24+
%(<a href="#{link}" rel="noopener noreferrer">#{super}</a>)
25+
else
26+
super
27+
end
2428
end
2529

2630
def table(header, body)

0 commit comments

Comments
 (0)