Skip to content
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
5 changes: 4 additions & 1 deletion lib/rdoc/markup/to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ def handle_RDOCLINK(url) # :nodoc:

gen_url CGI.escapeHTML(url), CGI.escapeHTML(text)
when /^rdoc-image:/
url, alt = $'.split(":", 2) # Split the string after "rdoc-image:" into url and alt
# Split the string after "rdoc-image:" into url and alt.
# "path/to/image.jpg:alt text" => ["path/to/image.jpg", "alt text"]
# "http://example.com/path/to/image.jpg:alt text" => ["http://example.com/path/to/image.jpg", "alt text"]
url, alt = $'.split(/:(?!\/)/, 2)
if alt && !alt.empty?
%[<img src="#{CGI.escapeHTML(url)}" alt="#{CGI.escapeHTML(alt)}">]
else
Expand Down
30 changes: 30 additions & 0 deletions test/rdoc/test_rdoc_markup_to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,36 @@ def test_convert_TIDYLINK_image
assert_not_include result, "<script>"
end

def test_convert_TIDYLINK_image_with_alt
result =
@to.convert '{rdoc-image:path/to/image.jpg:alt text}[http://example.com]'

expected =
"\n<p><a href=\"http://example.com\"><img src=\"path/to/image.jpg\" alt=\"alt text\"></a></p>\n"

assert_equal expected, result
end

def test_convert_TIDYLINK_image_external
result =
@to.convert '{rdoc-image:http://example.com/path/to/image.jpg}[http://example.com]'

expected =
"\n<p><a href=\"http://example.com\"><img src=\"http://example.com/path/to/image.jpg\"></a></p>\n"

assert_equal expected, result
end

def test_convert_TIDYLINK_image_external_with_alt
result =
@to.convert '{rdoc-image:http://example.com/path/to/image.jpg:alt text}[http://example.com]'

expected =
"\n<p><a href=\"http://example.com\"><img src=\"http://example.com/path/to/image.jpg\" alt=\"alt text\"></a></p>\n"

assert_equal expected, result
end

def test_convert_TIDYLINK_rdoc_label
result = @to.convert '{foo}[rdoc-label:foottext-1]'

Expand Down