Skip to content

Commit

Permalink
Merge pull request #283 from alphagov/fix-link-in-ordered-list
Browse files Browse the repository at this point in the history
Allow inline attachments in numbered lists
  • Loading branch information
brucebolt authored Aug 1, 2023
2 parents c893c09 + 068b2bc commit 9ca12d6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased

* Allow attachment links wtihin numbered lists ([#283](https://github.com/alphagov/govspeak/pull/283))

## 8.0.1

* Add margin-bottom to embedded attachments ([#281](https://github.com/alphagov/govspeak/pull/281))
Expand Down
2 changes: 1 addition & 1 deletion lib/govspeak.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def render_image(image)

extension("numbered list", /^[ \t]*((s\d+\.\s.*(?:\n|$))+)/) do |body|
body.gsub!(/s(\d+)\.\s(.*)(?:\n|$)/) do
"<li>#{Govspeak::Document.new(Regexp.last_match(2).strip).to_html}</li>\n"
"<li>#{Govspeak::Document.new(Regexp.last_match(2).strip, attachments: attachments).to_html}</li>\n"
end
%(<ol class="steps">\n#{body}</ol>)
end
Expand Down
24 changes: 24 additions & 0 deletions test/govspeak_attachment_link_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,28 @@ def render_govspeak(govspeak, attachments = [])
rendered = render_govspeak("[AttachmentLink: This is the name of my &%$@€? attachment]", [attachment])
assert_match(/Attachment Title/, rendered)
end

test "renders an attachment link inside a numbered list" do
attachment = {
id: "attachment.pdf",
url: "http://example.com/attachment.pdf",
title: "Attachment Title",
}

rendered = render_govspeak("s1. First item with [AttachmentLink: attachment.pdf]\ns2. Second item without attachment", [attachment])

expected_output = <<~TEXT
<ol class="steps">
<li>
<p>First item with <span class="gem-c-attachment-link">
<a class="govuk-link" href="http://example.com/attachment.pdf">Attachment Title</a> </span></p>
</li>
<li>
<p>Second item without attachment</p>
</li>
</ol>
TEXT

assert_equal(expected_output, rendered)
end
end

0 comments on commit 9ca12d6

Please sign in to comment.