1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/rdoc] 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>

https://github.com/ruby/rdoc/commit/05a2b2222b
This commit is contained in:
Peter Zhu 2022-03-08 17:02:35 -05:00 committed by git
parent 77f3f8a1d4
commit f62f913132
2 changed files with 17 additions and 1 deletions

View file

@ -14,12 +14,22 @@ class RDoc::CrossReference
CLASS_REGEXP_STR = '\\\\?((?:\:{2})?[A-Z]\w*(?:\:\:\w+)*)' 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. # Regular expression to match method references.
# #
# See CLASS_REGEXP_STR # 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 # Regular expressions matching text that should potentially have

View file

@ -17,6 +17,12 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
assert_equal para("<a href=\"C1.html\"><code>C1</code></a>"), result assert_equal para("<a href=\"C1.html\"><code>C1</code></a>"), result
end 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 def test_convert_CROSSREF_label
result = @to.convert 'C1@foo' result = @to.convert 'C1@foo'
assert_equal para("<a href=\"C1.html#class-C1-label-foo\">foo at <code>C1</code></a>"), result assert_equal para("<a href=\"C1.html#class-C1-label-foo\">foo at <code>C1</code></a>"), result