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

Links to document texts without "rdoc-ref:" prefix #800

Merged
merged 2 commits into from Mar 30, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/rdoc/markup/to_html.rb
Expand Up @@ -357,6 +357,10 @@ def gen_url url, text
url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
"<img src=\"#{url}\" />"
else
if scheme != 'link' and /\.(?:rb|rdoc|md)\z/i =~ url
url = url.sub(%r%\A([./]*)(.*)\z%) { "#$1#{$2.tr('.', '_')}.html" }
end

text = text.sub %r%^#{scheme}:/*%i, ''
text = text.sub %r%^[*\^](\d+)$%, '\1'

Expand Down
21 changes: 21 additions & 0 deletions test/rdoc/test_rdoc_markup_to_html.rb
Expand Up @@ -738,6 +738,27 @@ def test_gen_url_ssl_image_url
assert_equal '<img src="https://example.com/image.png" />', @to.gen_url('https://example.com/image.png', 'ignored')
end

def test_gen_url_rdoc_file
assert_equal '<a href="doc/example_rdoc.html">example</a>',
@to.gen_url('doc/example.rdoc', 'example')
assert_equal '<a href="../ex_doc/example_rdoc.html">example</a>',
@to.gen_url('../ex.doc/example.rdoc', 'example')
end

def test_gen_url_md_file
assert_equal '<a href="doc/example_md.html">example</a>',
@to.gen_url('doc/example.md', 'example')
assert_equal '<a href="../ex_doc/example_md.html">example</a>',
@to.gen_url('../ex.doc/example.md', 'example')
end

def test_gen_url_rb_file
assert_equal '<a href="doc/example_rb.html">example</a>',
@to.gen_url('doc/example.rb', 'example')
assert_equal '<a href="../ex_doc/example_rb.html">example</a>',
@to.gen_url('../ex.doc/example.rb', 'example')
end

def test_handle_regexp_HYPERLINK_link
target = RDoc::Markup::RegexpHandling.new 0, 'link:README.txt'

Expand Down
3 changes: 3 additions & 0 deletions test/rdoc/test_rdoc_top_level.rb
Expand Up @@ -157,6 +157,9 @@ def test_hash

def test_http_url
assert_equal 'prefix/path/top_level_rb.html', @top_level.http_url('prefix')

other_level = @store.add_file 'path.other/level.rb'
assert_equal 'prefix/path_other/level_rb.html', other_level.http_url('prefix')
end

def test_last_modified
Expand Down