History

Update Docs::Rdoc::CleanHtmlFilter to properly set the source section link when generated from Ruby 3.4+

Egor Dovnar committed 1 year ago

Commit de954d41 parent 543973a1 file · +13 −1Browse files

Unified · Split

lib/docs/filters/rdoc/clean_html.rb+13−1
@@ -30,12 +30,24 @@ module Docs · 29 unmodified lines
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)