Skip to content

Commit 59e038a

Browse files
committed
Fix Polars method signature rendering via Nokogiri HTML5 parser
1 parent 7d897c4 commit 59e038a

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

lib/docs/scrapers/polars.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,29 @@ class Polars < UrlScraper
3030
def get_latest_version(opts)
3131
get_latest_github_release('pola-rs', 'polars', opts).sub(/\Apy-/, '')
3232
end
33+
34+
private
35+
36+
def parse(response)
37+
if response.body.include?('class="sig')
38+
doc = Nokogiri::HTML5(response.body)
39+
doc.css('.sig').each do |node|
40+
node.css('.headerlink').remove
41+
node.css('.reference.external').each { |a| a.remove if a.text.strip == '[source]' }
42+
sig = node.text.gsub(/\s+/, ' ').strip
43+
if (m = sig.match(/\A(.+?\()\s*(.+?)\s*(\).*)\z/m))
44+
head, params, tail = m[1], m[2], m[3]
45+
split_params = params.split(/,\s+/).map { |p| p.sub(/,\z/, '') }.reject(&:empty?)
46+
sig = "#{head}\n #{split_params.join(",\n ")},\n#{tail}" unless split_params.empty?
47+
end
48+
pre = Nokogiri::XML::Node.new('pre', doc)
49+
pre['data-language'] = 'python'
50+
pre.content = sig
51+
node.replace(pre)
52+
end
53+
response.body.replace(doc.to_html)
54+
end
55+
super
56+
end
3357
end
3458
end

0 commit comments

Comments
 (0)