Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion lib/rdoc/markup/to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ 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
url_alt = $'
split_pos = url_alt.index(%r{:[^/]})
url = split_pos ? url_alt[0, split_pos] : url_alt
alt = split_pos ? url_alt[split_pos + 1, url_alt.size] : nil
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
Loading