Skip to content

Commit 05a2b22

Browse files
committed
Support crossref of methods with multiple arguments
For example, consider the following markup: C1#m(a, b) Before this patch, it generated this HTML: <p><a href=\"C1.html#method-i-m\"><code>C1#m</code></a>(a, b)</p> Which places the method arguments outside of the link. Now it generates this HTML: <a href=\"C1.html#method-i-m\"><code>C1#m(a, b)</code></a>
1 parent ef18a1c commit 05a2b22

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/rdoc/cross_reference.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,22 @@ class RDoc::CrossReference
1414

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

17+
##
18+
# Regular expression to match a single method argument.
19+
20+
METHOD_ARG_REGEXP_STR = '[\w.+*/=<>-]+'
21+
22+
##
23+
# Regular expression to match method arguments.
24+
25+
METHOD_ARGS_REGEXP_STR = /(?:\((?:#{METHOD_ARG_REGEXP_STR}(?:,\s*#{METHOD_ARG_REGEXP_STR})*)?\))?/.source
26+
1727
##
1828
# Regular expression to match method references.
1929
#
2030
# See CLASS_REGEXP_STR
2131

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

2434
##
2535
# Regular expressions matching text that should potentially have

test/rdoc/test_rdoc_markup_to_html_crossref.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ def test_convert_CROSSREF
1717
assert_equal para("<a href=\"C1.html\"><code>C1</code></a>"), result
1818
end
1919

20+
def test_convert_CROSSREF_method
21+
result = @to.convert 'C1#m(foo, bar, baz)'
22+
23+
assert_equal para("<a href=\"C1.html#method-i-m\"><code>C1#m(foo, bar, baz)</code></a>"), result
24+
end
25+
2026
def test_convert_CROSSREF_label
2127
result = @to.convert 'C1@foo'
2228
assert_equal para("<a href=\"C1.html#class-C1-label-foo\">foo at <code>C1</code></a>"), result

0 commit comments

Comments
 (0)