Skip to content

Commit

Permalink
Merge pull request #366 from alphagov/stop-images-with-no-alt-being-w…
Browse files Browse the repository at this point in the history
…rapped-in-links

Only wrap images with alt text in hyperlinks
  • Loading branch information
huwd authored Oct 22, 2024
2 parents 64d0492 + 9ebbd21 commit d888afa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ You need to
- Use hidden attribute to show/hide expiry notices instead of just CSS
- Only use dialog role for table of contents when it behaves like one (accessibility fix)
- Prevent interactive elements being obscured by sticky table of contents header
- Only wrap images with alt text in hyperlinks

## 3.5.0

Expand Down
8 changes: 6 additions & 2 deletions lib/govuk_tech_docs/tech_docs_html_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ def header(text, level)
%(<h#{level} id="#{anchor}">#{text}</h#{level}>\n)
end

def image(link, *args)
%(<a href="#{link}" rel="noopener noreferrer">#{super}</a>)
def image(link, title, alt_text)
if alt_text && !alt_text.strip.empty?
%(<a href="#{link}" rel="noopener noreferrer">#{super}</a>)
else
super
end
end

def table(header, body)
Expand Down

0 comments on commit d888afa

Please sign in to comment.