Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable cross reference in code #1240

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions lib/rdoc/markup/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,32 +195,39 @@ def in_tt?
@in_tt > 0
end

def tt_tag? attr_mask, reverse = false
each_attr_tag(attr_mask, reverse) do |tag|
return true if tt? tag
end
false
end

##
# Turns on tags for +item+ on +res+

def on_tags res, item
attr_mask = item.turn_on
return if attr_mask.zero?

@attr_tags.each do |tag|
if attr_mask & tag.bit != 0 then
res << annotate(tag.on)
@in_tt += 1 if tt? tag
end
each_attr_tag(item.turn_on) do |tag|
res << annotate(tag.on)
@in_tt += 1 if tt? tag
end
end

##
# Turns off tags for +item+ on +res+

def off_tags res, item
attr_mask = item.turn_off
each_attr_tag(item.turn_off, true) do |tag|
@in_tt -= 1 if tt? tag
res << annotate(tag.off)
end
end

def each_attr_tag attr_mask, reverse = false
return if attr_mask.zero?

@attr_tags.reverse_each do |tag|
@attr_tags.public_send(reverse ? :reverse_each : :each) do |tag|
if attr_mask & tag.bit != 0 then
@in_tt -= 1 if tt? tag
res << annotate(tag.off)
yield tag
end
end
end
Expand Down
39 changes: 39 additions & 0 deletions lib/rdoc/markup/to_html_crossref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,43 @@ def link name, text, code = true, rdoc_ref: false
end
end

def convert_flow(flow)
res = []

i = 0
while i < flow.size
item = flow[i]
i += 1
case item
when RDoc::Markup::AttrChanger then
# Make "+Class#method+" a cross reference
if tt_tag?(item.turn_on) and
String === (str = flow[i]) and
RDoc::Markup::AttrChanger === flow[i+1] and
tt_tag?(flow[i+1].turn_off, true) and
(@options.hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP).match?(str) and
(text = cross_reference str) != str
then
text = yield text, res if defined?(yield)
res << text
i += 2
next
end
off_tags res, item
on_tags res, item
when String then
text = convert_string(item)
text = yield text, res if defined?(yield)
res << text
when RDoc::Markup::RegexpHandling then
text = convert_regexp_handling(item)
text = yield text, res if defined?(yield)
res << text
else
raise "Unknown flow element: #{item.inspect}"
end
end

res.join('')
end
end
12 changes: 12 additions & 0 deletions test/rdoc/test_rdoc_markup_to_html_crossref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ def test_convert_CROSSREF
result = @to.convert 'C1'

assert_equal para("<a href=\"C1.html\"><code>C1</code></a>"), result

result = @to.convert '+C1+'
assert_equal para("<a href=\"C1.html\"><code>C1</code></a>"), result

result = @to.convert 'FOO'
assert_equal para("FOO"), result

result = @to.convert '+FOO+'
assert_equal para("<code>FOO</code>"), result

result = @to.convert '<tt># :stopdoc:</tt>:'
assert_equal para("<code># :stopdoc:</code>:"), result
end

def test_convert_CROSSREF_method
Expand Down
Loading