Showing the changes to lib/docs (3 of 17 files). Show all
Unified · Split
| @@ -4,26 +4,60 @@ module Docs · 3 unmodified lines | ||
| 4 | 4 | def call |
| 5 | 5 | @doc = at_css('#documentId .container') |
| 6 | 6 | |
| 7 | − css('.docinfo').remove | |
| 7 | + css('.docinfo', '.footer', 'blockquote > p:empty', '.link-seesrc').remove | |
| 8 | 8 | |
| 9 | − content = at_css('#content') | |
| 10 | − if content != nil | |
| 11 | − at_css('#content').remove_attribute('class') | |
| 12 | − @doc.add_child(at_css('#content').inner_html) | |
| 9 | + css('h1:not(.title), h2, h3, h4').each do |node| | |
| 10 | + node.name = node.name.sub(/\d/) { |i| i.to_i + 1 } | |
| 13 | 11 | end |
| 14 | 12 | |
| 15 | − css('> div.row').remove | |
| 13 | + if content = at_css('#content') | |
| 14 | + content.prepend_child at_css('h1.title') | |
| 15 | + @doc = content | |
| 16 | + end | |
| 16 | 17 | |
| 17 | − css('pre').each do |node| | |
| 18 | − node['data-language'] = 'nim' | |
| 18 | + if root_page? | |
| 19 | + at_css('h1').content = 'Nim Documentation' | |
| 19 | 20 | end |
| 20 | 21 | |
| 21 | − # remove link from headers | |
| 22 | 22 | css('h1 > a', 'h2 > a', 'h3 > a', 'h4 > a').each do |node| |
| 23 | − node.parent['id'] = node['id'] | |
| 24 | − node.parent.content = node.content | |
| 23 | + node.parent['id'] = node['id'] if node['id'] | |
| 24 | + node.before(node.children).remove | |
| 25 | + end | |
| 26 | + | |
| 27 | + css('a[name]').each do |node| | |
| 28 | + node.next_element['id'] = node['name'] | |
| 29 | + node.remove | |
| 30 | + end | |
| 31 | + | |
| 32 | + css('pre').each do |node| | |
| 33 | + node.content = node.content.strip | |
| 34 | + node['data-language'] = 'nim' unless node.content =~ /\A[\w\-\_\:\=\ ]+\z/ | |
| 25 | 35 | end |
| 26 | − | |
| 36 | + | |
| 37 | + css('tt').each do |node| | |
| 38 | + node.name = 'code' | |
| 39 | + end | |
| 40 | + | |
| 41 | + css('cite').each do |node| | |
| 42 | + node.name = 'em' | |
| 43 | + end | |
| 44 | + | |
| 45 | + css('.section').each do |node| | |
| 46 | + node.first_element_child['id'] = node['id'] if node['id'] | |
| 47 | + node.before(node.children).remove | |
| 48 | + end | |
| 49 | + | |
| 50 | + css('span.pre').each do |node| | |
| 51 | + node.before(node.children).remove | |
| 52 | + end | |
| 53 | + | |
| 54 | + css('blockquote > pre:only-child', 'blockquote > dl:only-child', 'blockquote > table').each do |node| | |
| 55 | + node.parent.before(node.parent.children).remove | |
| 56 | + end | |
| 57 | + | |
| 58 | + css('a', 'dl', 'table', 'code').remove_attr('class') | |
| 59 | + css('table').remove_attr('border') | |
| 60 | + | |
| 27 | 61 | doc |
| 28 | 62 | end |
| 29 | 63 | end |
| @@ -1,49 +1,62 @@ | ||
| 1 | 1 | module Docs |
| 2 | 2 | class Nim |
| 3 | 3 | class EntriesFilter < Docs::EntriesFilter |
| 4 | − def get_type | |
| 5 | − at_css('h1').content | |
| 4 | + def get_name | |
| 5 | + name = at_css('h1').content | |
| 6 | + name.remove! 'Module ' | |
| 7 | + name.remove! ' User Guide' | |
| 8 | + name.remove! ' User\'s manual' | |
| 9 | + name.remove! %r{ \-.*} | |
| 10 | + name.strip! | |
| 11 | + name | |
| 6 | 12 | end |
| 7 | 13 | |
| 8 | − def get_name | |
| 9 | − at_css('h1').content | |
| 14 | + def get_type | |
| 15 | + if name.include?('Tutorial') | |
| 16 | + 'Tutorial' | |
| 17 | + elsif slug == 'manual' | |
| 18 | + 'Manual' | |
| 19 | + elsif at_css('h1').content.include?('Module ') | |
| 20 | + name | |
| 21 | + else | |
| 22 | + 'Reference' | |
| 23 | + end | |
| 10 | 24 | end |
| 11 | 25 | |
| 12 | 26 | def additional_entries |
| 13 | 27 | entries = [] |
| 14 | − if get_name.start_with? 'Module ' | |
| 15 | − module_name = get_name[7..-1] | |
| 16 | − css('div .section').map do |node| | |
| 17 | − section_node = node.at_css('h1 a') | |
| 18 | − if section_node != nil | |
| 19 | − section_name = section_node.content.strip | |
| 20 | − items_node = node.at_css('dl.item') | |
| 21 | − if items_node != nil | |
| 22 | − items_node.css('dt a').map do |item_node| | |
| 23 | − item_name = item_node['name'] | |
| 24 | − if item_name.include? ',' | |
| 25 | − item_name = item_name.sub(',', '(') + ')' | |
| 26 | − end | |
| 27 | − entries << [module_name + '.' + item_name, item_node.parent['id']] | |
| 28 | − end | |
| 29 | − end | |
| 28 | + | |
| 29 | + if at_css('h1').content.include?('Module ') | |
| 30 | + css('#toc-list > li > .simple-toc-section').each do |node| | |
| 31 | + type = node.previous_element.content.strip | |
| 32 | + | |
| 33 | + node.css('a.reference:not(.reference-toplevel)').each do |n| | |
| 34 | + n.css('span').remove | |
| 35 | + name = n.content.strip | |
| 36 | + name << '()' if (type == 'Procs' || type == 'Templates') && !name.include?('`') | |
| 37 | + name.remove! '`' | |
| 38 | + name.prepend "#{self.name}." | |
| 39 | + id = n['href'].remove('#') | |
| 40 | + entries << [name, id] unless entries.any? { |e| e[0] == name } | |
| 30 | 41 | end |
| 31 | 42 | end |
| 32 | − else | |
| 33 | − css('h1', 'h2', 'h3').map do |node| | |
| 34 | − id = node['id'] | |
| 43 | + elsif slug == 'manual' | |
| 44 | + css('#toc-list > li > a').each do |node| | |
| 35 | 45 | name = node.content.strip |
| 36 | − if id != nil | |
| 37 | − entries << [name, id] | |
| 38 | − else | |
| 39 | − a = node.at_css('a') | |
| 40 | − if a != nil | |
| 41 | − id = a['id'] | |
| 42 | − entries << [name, id] | |
| 43 | − end | |
| 46 | + next if name.start_with?('About') | |
| 47 | + id = node['href'].remove('#') | |
| 48 | + entries << [name, id] | |
| 49 | + end | |
| 50 | + | |
| 51 | + css('#toc-list > ul').each do |node| | |
| 52 | + type = node.previous_element.content.strip | |
| 53 | + | |
| 54 | + node.css('> li > a').each do |n| | |
| 55 | + entries << [n.content.strip, n['href'].remove('#'), "Manual: #{type}"] | |
| 44 | 56 | end |
| 45 | 57 | end |
| 46 | 58 | end |
| 59 | + | |
| 47 | 60 | entries |
| 48 | 61 | end |
| 49 | 62 | end |
| @@ -2,20 +2,20 @@ module Docs · 1 unmodified line | ||
| 2 | 2 | class Nim < UrlScraper |
| 3 | 3 | self.type = 'nim' |
| 4 | 4 | self.release = '0.17.0' |
| 5 | + self.base_url = 'https://nim-lang.org/docs/' | |
| 6 | + self.root_path = 'overview.html' | |
| 5 | 7 | self.links = { |
| 6 | 8 | home: 'https://nim-lang.org/', |
| 7 | 9 | code: 'https://github.com/nim-lang/Nim' |
| 8 | 10 | } |
| 9 | − self.base_url = 'https://nim-lang.org/' | |
| 10 | − self.root_path = 'docs/overview.html' | |
| 11 | 11 | |
| 12 | − html_filters.push 'nim/entries', 'nim/clean_html' | |
| 13 | − | |
| 14 | − options[:skip] = %w(cdn-cgi/l/email-protection docs/theindex.html docs/docgen.txt) | |
| 12 | + html_filters.push 'nim/entries', 'nim/clean_html' | |
| 13 | + | |
| 14 | + options[:skip] = %w(theindex.html docgen.txt) | |
| 15 | + | |
| 15 | 16 | options[:attribution] = <<-HTML |
| 16 | 17 | © 2006–2017 Andreas Rumpf<br> |
| 17 | − All rights reserved. Licensed under the MIT License. | |
| 18 | + Licensed under the MIT License. | |
| 18 | 19 | HTML |
| 19 | − | |
| 20 | 20 | end |
| 21 | −end | |
| 21 | +end | |