Skip to content

Commit de954d4

Browse files
committed
Update Docs::Rdoc::CleanHtmlFilter to properly set the source section link when generated from Ruby 3.4+
1 parent 543973a commit de954d4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/docs/filters/rdoc/clean_html.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,24 @@ def other
3030
node.remove_attribute 'id'
3131
end
3232

33-
# Convert "click to toggle source" into a link
33+
# (RDoc prior to Ruby 3.4) Convert "click to toggle source" into a link
3434
css('.method-click-advice').each do |node|
3535
node.name = 'a'
3636
node.content = 'Show source'
3737
end
3838

39+
# (RDoc for Ruby 3.4+) Add a "Show source" link
40+
css('.method-source-toggle').each do |node|
41+
link_node = Nokogiri::XML::Node.new('a', doc.document)
42+
link_node.content = 'Show source'
43+
link_node['class'] = 'method-click-advice'
44+
45+
node.parent.parent.at_css('.method-heading').add_child(link_node)
46+
end
47+
48+
# (RDoc for Ruby 3.4+) Remove the additional "Source" toggle from the page
49+
css('.method-controls').remove
50+
3951
# Add class to differentiate Ruby code from C code
4052
css('.method-source-code').each do |node|
4153
node.parent.prepend_child(node)

0 commit comments

Comments
 (0)