Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All links should open in a new tab #11

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Released

### [0.2.0] - 2023-08-015
- All links should open in a new tab [#9](https://github.com/alphagov/govuk-forms-markdown/issues/9)

### [0.1.0] - 2023-08-03

- Initial release
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
govuk-forms-markdown (0.1.0)
govuk-forms-markdown (0.2.0)
redcarpet (~> 3.6)

GEM
Expand Down
2 changes: 1 addition & 1 deletion lib/govuk-forms-markdown/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def triple_emphasis(text)

def link(link, title, content)
title_attribute = title.nil? ? "" : " title=\"#{title}\""
%(<a href="#{link}" class="govuk-link"#{title_attribute}>#{content}</a>)
%(<a href="#{link}" class="govuk-link"#{title_attribute} rel="noreferrer noopener" target="_blank">#{content}</a>)
end

def list(contents, list_type)
Expand Down
2 changes: 1 addition & 1 deletion lib/govuk-forms-markdown/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module GovukFormsMarkdown
VERSION = "0.1.0"
VERSION = "0.2.0"
end
2 changes: 1 addition & 1 deletion lib/govuk_forms_markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module GovukFormsMarkdown
class Error < StandardError; end

def self.render(markdown)
renderer = GovukFormsMarkdown::Renderer.new({ link_attributes: { class: "govuk-link" } })
renderer = GovukFormsMarkdown::Renderer.new({ link_attributes: { class: "govuk-link", rel: "noreferrer noopener", target: "_blank" } })
Redcarpet::Markdown.new(renderer, no_intra_emphasis: true).render(markdown).strip
end
end
4 changes: 2 additions & 2 deletions spec/govuk-forms-markdown/govuk_forms_markdown_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@

it "renders a URL in angle brackets with GOV.UK classes" do
expect(render("<https://www.gov.uk/help>")).to eq(
'<p class="govuk-body"><a href="https://www.gov.uk/help" class="govuk-link">https://www.gov.uk/help</a></p>',
'<p class="govuk-body"><a href="https://www.gov.uk/help" class="govuk-link" rel="noreferrer noopener" target="_blank">https://www.gov.uk/help</a></p>',
)
end

it "renders an email address in angle brackets with GOV.UK classes" do
expect(render("<[email protected]>")).to eq(
'<p class="govuk-body"><a href="mailto:[email protected]" class="govuk-link">[email protected]</a></p>',
'<p class="govuk-body"><a href="mailto:[email protected]" class="govuk-link" rel="noreferrer noopener" target="_blank">[email protected]</a></p>',
)
end

Expand Down
4 changes: 2 additions & 2 deletions spec/govuk-forms-markdown/renderer/link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

context "when there is no title" do
it "renders a link" do
expect(renderer.link("https://example.com", nil, "Link content").strip).to eq "<a href=\"https://example.com\" class=\"govuk-link\">Link content</a>"
expect(renderer.link("https://example.com", nil, "Link content").strip).to eq "<a href=\"https://example.com\" class=\"govuk-link\" rel=\"noreferrer noopener\" target=\"_blank\">Link content</a>"
end
end

context "when there is a title" do
it "renders a link" do
expect(renderer.link("https://example.com", "Link title", "Link content").strip).to eq "<a href=\"https://example.com\" class=\"govuk-link\" title=\"Link title\">Link content</a>"
expect(renderer.link("https://example.com", "Link title", "Link content").strip).to eq "<a href=\"https://example.com\" class=\"govuk-link\" title=\"Link title\" rel=\"noreferrer noopener\" target=\"_blank\">Link content</a>"
end
end
end
Expand Down