Skip to content

Commit e8c56dd

Browse files
authored
Merge pull request #764 from aycabta/process-crossref-before-tidylink
Process crossref before tidylink
2 parents daac9d0 + 0f47baf commit e8c56dd

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

lib/rdoc/markup/to_html.rb

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,7 @@ def initialize options, markup = nil
5252
@th = nil
5353
@hard_break = "<br>\n"
5454

55-
# external links
56-
@markup.add_regexp_handling(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w/,
57-
:HYPERLINK)
58-
59-
add_regexp_handling_RDOCLINK
60-
add_regexp_handling_TIDYLINK
55+
init_regexp_handlings
6156

6257
init_tags
6358
end
@@ -66,6 +61,24 @@ def initialize options, markup = nil
6661
#
6762
# These methods are used by regexp handling markup added by RDoc::Markup#add_regexp_handling.
6863

64+
##
65+
# Adds regexp handlings.
66+
67+
def init_regexp_handlings
68+
# external links
69+
@markup.add_regexp_handling(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w/,
70+
:HYPERLINK)
71+
init_link_notation_regexp_handlings
72+
end
73+
74+
##
75+
# Adds regexp handlings about link notations.
76+
77+
def init_link_notation_regexp_handlings
78+
add_regexp_handling_RDOCLINK
79+
add_regexp_handling_TIDYLINK
80+
end
81+
6982
def handle_RDOCLINK url # :nodoc:
7083
case url
7184
when /^rdoc-ref:/

lib/rdoc/markup/to_html_crossref.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,18 @@ def initialize(options, from_path, context, markup = nil)
3939
@hyperlink_all = @options.hyperlink_all
4040
@show_hash = @options.show_hash
4141

42-
crossref_re = @hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
42+
@cross_reference = RDoc::CrossReference.new @context
43+
end
44+
45+
def init_link_notation_regexp_handlings
46+
add_regexp_handling_RDOCLINK
47+
48+
# The crossref must be linked before tidylink because Klass.method[:sym]
49+
# will be processed as a tidylink first and will be broken.
50+
crossref_re = @options.hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
4351
@markup.add_regexp_handling crossref_re, :CROSSREF
4452

45-
@cross_reference = RDoc::CrossReference.new @context
53+
add_regexp_handling_TIDYLINK
4654
end
4755

4856
##

test/rdoc/test_rdoc_markup_to_html_crossref.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ def test_handle_regexp_CROSSREF_show_hash_false
151151
REGEXP_HANDLING('#m')
152152
end
153153

154+
def test_handle_regexp_CROSSREF_with_arg_looks_like_TIDYLINK
155+
result = @to.convert 'C1.m[:sym]'
156+
157+
assert_equal para("<a href=\"C1.html#method-c-m\"><code>C1.m[:sym]</code></a>"), result,
158+
'C1.m[:sym]'
159+
end
160+
154161
def test_handle_regexp_HYPERLINK_rdoc
155162
readme = @store.add_file 'README.txt'
156163
readme.parser = RDoc::Parser::Simple

0 commit comments

Comments
 (0)