Skip to content

Commit 31f76e1

Browse files
committed
Fix ToHtmlCrossref#convert_flow for backslash in tt tag
1 parent 88db613 commit 31f76e1

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

lib/rdoc/markup/to_html_crossref.rb

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,24 @@ def convert_flow(flow)
197197
if tt_tag?(item.turn_on) and
198198
String === (str = flow[i]) and
199199
RDoc::Markup::AttrChanger === flow[i+1] and
200-
tt_tag?(flow[i+1].turn_off, true) and
201-
(@options.hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP).match?(str) and
202-
(text = cross_reference str) != str
200+
tt_tag?(flow[i+1].turn_off, true)
203201
then
204-
text = yield text, res if defined?(yield)
205-
res << text
206-
i += 2
207-
next
202+
crossref_re = @options.hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
203+
204+
if match = crossref_re.match(str)
205+
trailing = str[match.end(1)..-1] || ''
206+
207+
if match.begin(1).zero? and
208+
trailing.match?(/\A[[:punct:]\s]*\z/) and
209+
trailing !~ /[#@]/ and
210+
(text = cross_reference str) != str
211+
then
212+
text = yield text, res if defined?(yield)
213+
res << text
214+
i += 2
215+
next
216+
end
217+
end
208218
end
209219
off_tags res, item
210220
on_tags res, item

test/rdoc/rdoc_markup_to_html_crossref_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,28 @@ def test_convert_CROSSREF
3333
assert_equal para("<code># :stopdoc:</code>:"), result
3434
end
3535

36+
def test_convert_CROSSREF_backslash_in_tt
37+
@options.hyperlink_all = false
38+
39+
formatter = RDoc::Markup::ToHtmlCrossref.new @options, 'C9.html', @c9_b
40+
result = formatter.convert '<tt>C1</tt>'
41+
42+
assert_equal para('<a href="C1.html"><code>C1</code></a>'), result
43+
44+
formatter = RDoc::Markup::ToHtmlCrossref.new @options, 'C9.html', @c9_b
45+
result = formatter.convert '<tt>.bar.hello()</tt>'
46+
47+
assert_equal para('<code>.bar.hello()</code>'), result
48+
49+
formatter = RDoc::Markup::ToHtmlCrossref.new @options, 'C9.html', @c9_b
50+
result = formatter.convert '<tt>.bar.hello(\)</tt>'
51+
52+
formatter = RDoc::Markup::ToHtmlCrossref.new @options, 'Foo.html', foo
53+
result = formatter.convert '<tt>.bar.hello(\\)</tt>'
54+
55+
assert_equal para('<code>.bar.hello(\\)</code>'), result
56+
end
57+
3658
def test_convert_CROSSREF_ignored_excluded_words
3759
@options.autolink_excluded_words = ['C1']
3860

0 commit comments

Comments
 (0)