|
|
|
@ -2,100 +2,46 @@ module Docs
|
|
|
|
|
class Pygame
|
|
|
|
|
class CleanHtmlFilter < Filter
|
|
|
|
|
def call
|
|
|
|
|
@doc = at_css '.body'
|
|
|
|
|
|
|
|
|
|
if root_page?
|
|
|
|
|
# remove unneeded stuff
|
|
|
|
|
at_css('.modindex-jumpbox').remove
|
|
|
|
|
css('[role="navigation"],.pcap, .cap, .footer').remove
|
|
|
|
|
# table -> list
|
|
|
|
|
list = at_css('table')
|
|
|
|
|
list.replace(list.children)
|
|
|
|
|
list.name = 'ul'
|
|
|
|
|
css('tr').each do |row|
|
|
|
|
|
row.name = 'li'
|
|
|
|
|
row.remove_attribute('class')
|
|
|
|
|
end
|
|
|
|
|
at_css('h1').content = 'Pygame'
|
|
|
|
|
return doc
|
|
|
|
|
end
|
|
|
|
|
@doc = at_css('.body')
|
|
|
|
|
root_page? ? root : other
|
|
|
|
|
doc
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# remove unwanted stuff
|
|
|
|
|
# .headerlink => ¶ after links
|
|
|
|
|
# .toc => table of content
|
|
|
|
|
# .tooltip-content => tooltips after links to functions
|
|
|
|
|
css('table.toc.docutils, .headerlink, .tooltip-content').remove
|
|
|
|
|
def root
|
|
|
|
|
at_css('h1').content = 'Pygame'
|
|
|
|
|
|
|
|
|
|
# Remove wrapper .section
|
|
|
|
|
section = at_css('.section')
|
|
|
|
|
definition = at_css('.definition')
|
|
|
|
|
definition['id'] = section['id']
|
|
|
|
|
section.replace(section.children)
|
|
|
|
|
# remove unneeded stuff
|
|
|
|
|
at_css('.modindex-jumpbox').remove
|
|
|
|
|
css('[role="navigation"], .pcap, .cap, .footer').remove
|
|
|
|
|
css('tr > td:first-child').remove
|
|
|
|
|
|
|
|
|
|
# Format code for it be highlighted
|
|
|
|
|
css('.highlight-default.notranslate').each do |node|
|
|
|
|
|
pre = node.at_css('pre')
|
|
|
|
|
node.replace(pre)
|
|
|
|
|
# gets rid of the already existing syntax highlighting
|
|
|
|
|
pre.content = pre.content
|
|
|
|
|
pre['class'] = 'language-python'
|
|
|
|
|
pre['data-language'] = "python"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# change descriptions of functions/attributes to blockquote
|
|
|
|
|
css('.line-block').each do |node|
|
|
|
|
|
node.name = 'blockquote'
|
|
|
|
|
# Unitalicize package descriptions
|
|
|
|
|
css('td > em').each do |node|
|
|
|
|
|
node.parent.content = node.content
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# change functions
|
|
|
|
|
css('.definition').each do |d|
|
|
|
|
|
def other
|
|
|
|
|
css('> :not(.section), table.toc.docutils, .tooltip-content').remove
|
|
|
|
|
|
|
|
|
|
# the header is the function/attribute name. It might look something like
|
|
|
|
|
# this:
|
|
|
|
|
# pygame.image.load()
|
|
|
|
|
# It'll end up being something like this:
|
|
|
|
|
# pygame.image.load(filename) -> Surface
|
|
|
|
|
# pygame.image.load(fileobj, namehint="") -> Surface
|
|
|
|
|
# Remove code tag from function, class, method, module, etc.
|
|
|
|
|
css('dl > dt').each do |node|
|
|
|
|
|
node.content = node.content
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
header = d.at_css('dt.title')
|
|
|
|
|
if d['class'].include?('class') or d['class'].include?('module')
|
|
|
|
|
header.name = 'h1'
|
|
|
|
|
@section = header.content.strip
|
|
|
|
|
else
|
|
|
|
|
header.name = 'h3'
|
|
|
|
|
end
|
|
|
|
|
# save the original header
|
|
|
|
|
initial_header = header.content.strip
|
|
|
|
|
# save the real name for the entries
|
|
|
|
|
header['data-name'] = initial_header
|
|
|
|
|
# empty the header
|
|
|
|
|
if header.name == 'h3'
|
|
|
|
|
header.inner_html = ''
|
|
|
|
|
end
|
|
|
|
|
# to replace it with the signatures
|
|
|
|
|
next_el = header.next_element
|
|
|
|
|
signatures = next_el.css('.signature')
|
|
|
|
|
signatures.each do |sig|
|
|
|
|
|
sig.name = 'code'
|
|
|
|
|
if header.name == 'h3'
|
|
|
|
|
sig.parent = header
|
|
|
|
|
# the signature don't contain pygame.module. I think it's better
|
|
|
|
|
# to display them, as it avoids confusion with methods (have a
|
|
|
|
|
# look at the pygame.Rect page)
|
|
|
|
|
if initial_header.start_with?(@section)
|
|
|
|
|
sig.content = @section + '.' + sig.text
|
|
|
|
|
end
|
|
|
|
|
# separate the signatures on different lines.
|
|
|
|
|
header.add_child "<br>"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
css('> .section > dl > dt').each do |node|
|
|
|
|
|
node.name = 'h1'
|
|
|
|
|
node.parent.parent.before(node)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
css('> dl', '> dl > dd', 'h1 code').each do |node|
|
|
|
|
|
node.before(node.children).remove
|
|
|
|
|
# Format code for it be highlighted
|
|
|
|
|
css('.highlight-default.notranslate').each do |node|
|
|
|
|
|
node.name = 'pre'
|
|
|
|
|
node.content = node.content.strip
|
|
|
|
|
node['class'] = 'language-python'
|
|
|
|
|
node['data-language'] = 'python'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
doc
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|