Skip to content

Commit

Permalink
Allow a label in a link to another document text
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Jun 30, 2021
1 parent ec17a3e commit 85bb2d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rdoc/markup/to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ 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" }
if scheme != 'link' and %r%\A([./]*+)(.*?\.)(rb|rdoc|md)(?=\z|#)%i =~ url
url = "#$1#{$2.tr('.', '_')}#$3.html#{$'}"
end

text = text.sub %r%^#{scheme}:/*%i, ''
Expand Down
12 changes: 12 additions & 0 deletions test/rdoc/test_rdoc_markup_to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -743,20 +743,32 @@ def test_gen_url_rdoc_file
@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')
assert_equal '<a href="doc/example_rdoc.html#label-one">example</a>',
@to.gen_url('doc/example.rdoc#label-one', 'example')
assert_equal '<a href="../ex_doc/example_rdoc.html#label-two">example</a>',
@to.gen_url('../ex.doc/example.rdoc#label-two', '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')
assert_equal '<a href="doc/example_md.html#label-one">example</a>',
@to.gen_url('doc/example.md#label-one', 'example')
assert_equal '<a href="../ex_doc/example_md.html#label-two">example</a>',
@to.gen_url('../ex.doc/example.md#label-two', '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')
assert_equal '<a href="doc/example_rb.html#label-one">example</a>',
@to.gen_url('doc/example.rb#label-one', 'example')
assert_equal '<a href="../ex_doc/example_rb.html#label-two">example</a>',
@to.gen_url('../ex.doc/example.rb#label-two', 'example')
end

def test_handle_regexp_HYPERLINK_link
Expand Down

0 comments on commit 85bb2d3

Please sign in to comment.