From ecdc9c8431c0359cf853984d2d399115b37ea078 Mon Sep 17 00:00:00 2001 From: Thibaut Date: Sat, 8 Mar 2014 12:10:42 -0500 Subject: [PATCH] Improve D3.js scraper (3.4.3) --- lib/docs/filters/d3/clean_html.rb | 15 +++++++++++++++ lib/docs/scrapers/d3.rb | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/docs/filters/d3/clean_html.rb b/lib/docs/filters/d3/clean_html.rb index 61554ce1..a760b140 100644 --- a/lib/docs/filters/d3/clean_html.rb +++ b/lib/docs/filters/d3/clean_html.rb @@ -30,6 +30,21 @@ module Docs node.remove end + # Make headings for function definitions and add "id" attributes + css('p > a:first-child').each do |node| + next unless node['name'] || node.content == '#' + parent = node.parent + parent.name = 'h6' + parent['id'] = (node['name'] || node['href'].sub(/\A.+#/, '')).sub('wiki-', '') + parent.css('a[name]').remove + node.remove + end + + # Fix internal links + css('a[href]').each do |node| + node['href'] = node['href'].sub(/#wiki\-(\w+?)\z/, '#\1') + end + # Remove code highlighting css('.highlight > pre').each do |node| node.content = node.content diff --git a/lib/docs/scrapers/d3.rb b/lib/docs/scrapers/d3.rb index cc08ee43..35fca733 100644 --- a/lib/docs/scrapers/d3.rb +++ b/lib/docs/scrapers/d3.rb @@ -3,7 +3,7 @@ module Docs self.name = 'D3.js' self.slug = 'd3' self.type = 'd3' - self.version = '3.4.2' + self.version = '3.4.3' self.base_url = 'https://github.com/mbostock/d3/wiki/' self.root_path = 'API-Reference'