| @@ -2,100 +2,46 @@ module Docs · 1 unmodified line |
| 2 | 2 | class Pygame |
| 3 | 3 | class CleanHtmlFilter < Filter |
| 4 | 4 | def call |
| 5 | | − @doc = at_css '.body' |
| 6 | | − |
| 7 | | − if root_page? |
| 8 | | − # remove unneeded stuff |
| 9 | | − at_css('.modindex-jumpbox').remove |
| 10 | | − css('[role="navigation"],.pcap, .cap, .footer').remove |
| 11 | | − # table -> list |
| 12 | | − list = at_css('table') |
| 13 | | − list.replace(list.children) |
| 14 | | − list.name = 'ul' |
| 15 | | − css('tr').each do |row| |
| 16 | | − row.name = 'li' |
| 17 | | − row.remove_attribute('class') |
| 18 | | − end |
| 19 | | − at_css('h1').content = 'Pygame' |
| 20 | | − return doc |
| 21 | | − end |
| 5 | + @doc = at_css('.body') |
| 6 | + root_page? ? root : other |
| 7 | + doc |
| 8 | + end |
| 22 | 9 | |
| 23 | | − # remove unwanted stuff |
| 24 | | − # .headerlink => ¶ after links |
| 25 | | − # .toc => table of content |
| 26 | | − # .tooltip-content => tooltips after links to functions |
| 27 | | − css('table.toc.docutils, .headerlink, .tooltip-content').remove |
| 10 | + def root |
| 11 | + at_css('h1').content = 'Pygame' |
| 28 | 12 | |
| 29 | | − # Remove wrapper .section |
| 30 | | − section = at_css('.section') |
| 31 | | − definition = at_css('.definition') |
| 32 | | − definition['id'] = section['id'] |
| 33 | | − section.replace(section.children) |
| 13 | + # remove unneeded stuff |
| 14 | + at_css('.modindex-jumpbox').remove |
| 15 | + css('[role="navigation"], .pcap, .cap, .footer').remove |
| 16 | + css('tr > td:first-child').remove |
| 34 | 17 | |
| 35 | | − # Format code for it be highlighted |
| 36 | | − css('.highlight-default.notranslate').each do |node| |
| 37 | | − pre = node.at_css('pre') |
| 38 | | − node.replace(pre) |
| 39 | | − # gets rid of the already existing syntax highlighting |
| 40 | | − pre.content = pre.content |
| 41 | | − pre['class'] = 'language-python' |
| 42 | | − pre['data-language'] = "python" |
| 43 | | − end |
| 44 | | − |
| 45 | | − # change descriptions of functions/attributes to blockquote |
| 46 | | − css('.line-block').each do |node| |
| 47 | | − node.name = 'blockquote' |
| 18 | + # Unitalicize package descriptions |
| 19 | + css('td > em').each do |node| |
| 20 | + node.parent.content = node.content |
| 48 | 21 | end |
| 22 | + end |
| 49 | 23 | |
| 50 | | − # change functions |
| 51 | | − css('.definition').each do |d| |
| 24 | + def other |
| 25 | + css('> :not(.section), table.toc.docutils, .tooltip-content').remove |
| 52 | 26 | |
| 53 | | − # the header is the function/attribute name. It might look something like |
| 54 | | − # this: |
| 55 | | − # pygame.image.load() |
| 56 | | − # It'll end up being something like this: |
| 57 | | − # pygame.image.load(filename) -> Surface |
| 58 | | − # pygame.image.load(fileobj, namehint="") -> Surface |
| 27 | + # Remove code tag from function, class, method, module, etc. |
| 28 | + css('dl > dt').each do |node| |
| 29 | + node.content = node.content |
| 30 | + end |
| 59 | 31 | |
| 60 | | − header = d.at_css('dt.title') |
| 61 | | − if d['class'].include?('class') or d['class'].include?('module') |
| 62 | | − header.name = 'h1' |
| 63 | | − @section = header.content.strip |
| 64 | | − else |
| 65 | | − header.name = 'h3' |
| 66 | | − end |
| 67 | | − # save the original header |
| 68 | | − initial_header = header.content.strip |
| 69 | | − # save the real name for the entries |
| 70 | | − header['data-name'] = initial_header |
| 71 | | − # empty the header |
| 72 | | − if header.name == 'h3' |
| 73 | | − header.inner_html = '' |
| 74 | | − end |
| 75 | | − # to replace it with the signatures |
| 76 | | − next_el = header.next_element |
| 77 | | − signatures = next_el.css('.signature') |
| 78 | | − signatures.each do |sig| |
| 79 | | − sig.name = 'code' |
| 80 | | − if header.name == 'h3' |
| 81 | | − sig.parent = header |
| 82 | | − # the signature don't contain pygame.module. I think it's better |
| 83 | | − # to display them, as it avoids confusion with methods (have a |
| 84 | | − # look at the pygame.Rect page) |
| 85 | | − if initial_header.start_with?(@section) |
| 86 | | − sig.content = @section + '.' + sig.text |
| 87 | | − end |
| 88 | | − # separate the signatures on different lines. |
| 89 | | − header.add_child "<br>" |
| 90 | | − end |
| 91 | | − end |
| 32 | + css('> .section > dl > dt').each do |node| |
| 33 | + node.name = 'h1' |
| 34 | + node.parent.parent.before(node) |
| 92 | 35 | end |
| 93 | 36 | |
| 94 | | − css('> dl', '> dl > dd', 'h1 code').each do |node| |
| 95 | | − node.before(node.children).remove |
| 37 | + # Format code for it be highlighted |
| 38 | + css('.highlight-default.notranslate').each do |node| |
| 39 | + node.name = 'pre' |
| 40 | + node.content = node.content.strip |
| 41 | + node['class'] = 'language-python' |
| 42 | + node['data-language'] = 'python' |
| 96 | 43 | end |
| 97 | 44 | |
| 98 | | − doc |
| 99 | 45 | end |
| 100 | 46 | end |
| 101 | 47 | end |