From de954d432227c056ee3e3e67db63d91d3ca6ee69 Mon Sep 17 00:00:00 2001 From: Egor Dovnar Date: Wed, 26 Mar 2025 04:19:50 +0300 Subject: [PATCH] Update Docs::Rdoc::CleanHtmlFilter to properly set the source section link when generated from Ruby 3.4+ --- lib/docs/filters/rdoc/clean_html.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/docs/filters/rdoc/clean_html.rb b/lib/docs/filters/rdoc/clean_html.rb index ac836d1948..ff6d76604d 100644 --- a/lib/docs/filters/rdoc/clean_html.rb +++ b/lib/docs/filters/rdoc/clean_html.rb @@ -30,12 +30,24 @@ def other node.remove_attribute 'id' end - # Convert "click to toggle source" into a link + # (RDoc prior to Ruby 3.4) Convert "click to toggle source" into a link css('.method-click-advice').each do |node| node.name = 'a' node.content = 'Show source' end + # (RDoc for Ruby 3.4+) Add a "Show source" link + css('.method-source-toggle').each do |node| + link_node = Nokogiri::XML::Node.new('a', doc.document) + link_node.content = 'Show source' + link_node['class'] = 'method-click-advice' + + node.parent.parent.at_css('.method-heading').add_child(link_node) + end + + # (RDoc for Ruby 3.4+) Remove the additional "Source" toggle from the page + css('.method-controls').remove + # Add class to differentiate Ruby code from C code css('.method-source-code').each do |node| node.parent.prepend_child(node)