Skip to content

Commit

Permalink
Merge pull request #871 from peterzhu2118/crossref-method-args
Browse files Browse the repository at this point in the history
Support crossref of methods with multiple arguments
  • Loading branch information
peterzhu2118 committed Mar 9, 2022
2 parents ef18a1c + 05a2b22 commit 98b4e65
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/rdoc/cross_reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,22 @@ class RDoc::CrossReference

CLASS_REGEXP_STR = '\\\\?((?:\:{2})?[A-Z]\w*(?:\:\:\w+)*)'

##
# Regular expression to match a single method argument.

METHOD_ARG_REGEXP_STR = '[\w.+*/=<>-]+'

##
# Regular expression to match method arguments.

METHOD_ARGS_REGEXP_STR = /(?:\((?:#{METHOD_ARG_REGEXP_STR}(?:,\s*#{METHOD_ARG_REGEXP_STR})*)?\))?/.source

##
# Regular expression to match method references.
#
# See CLASS_REGEXP_STR

METHOD_REGEXP_STR = '([A-Za-z]\w*[!?=]?|%|=(?:==?|~)|![=~]|\[\]=?|<(?:<|=>?)?|>[>=]?|[-+!]@?|\*\*?|[/%`|&^~])(?:\([\w.+*/=<>-]*\))?'
METHOD_REGEXP_STR = /([A-Za-z]\w*[!?=]?|%|=(?:==?|~)|![=~]|\[\]=?|<(?:<|=>?)?|>[>=]?|[-+!]@?|\*\*?|[\/%`|&^~])#{METHOD_ARGS_REGEXP_STR}/.source

##
# Regular expressions matching text that should potentially have
Expand Down
6 changes: 6 additions & 0 deletions test/rdoc/test_rdoc_markup_to_html_crossref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ def test_convert_CROSSREF
assert_equal para("<a href=\"C1.html\"><code>C1</code></a>"), result
end

def test_convert_CROSSREF_method
result = @to.convert 'C1#m(foo, bar, baz)'

assert_equal para("<a href=\"C1.html#method-i-m\"><code>C1#m(foo, bar, baz)</code></a>"), result
end

def test_convert_CROSSREF_label
result = @to.convert 'C1@foo'
assert_equal para("<a href=\"C1.html#class-C1-label-foo\">foo at <code>C1</code></a>"), result
Expand Down

0 comments on commit 98b4e65

Please sign in to comment.