from docutils import nodes from wikiwriter import HTMLTranslatorBase CONTENTS = [ ('Home - News', 'Home Page', 'index.html'), ('Intro', 'Introduction', 'introduction.html'), ('Doc', 'Documentation', 'doc.html'), ('Download', 'Download', 'download.html'), ('Source (subversion)', None, 'http://codespeak.net/svn/psyco/dist/'), ('SF', None, 'http://sourceforge.net/projects/psyco'), ('Links', 'Links', 'links.html'), ] FOOTER = ''' SourceForge Logo ''' CUSTOM_HACK_HTML = '''
psyco snapshot
''' class HTMLTranslator(HTMLTranslatorBase): TDOpen = ( '''   ''') TDClose = ( '''
''') def __init__(self, doctree, stylesheet='ignored', title=0): HTMLTranslatorBase.__init__(self, doctree) self.title = title self.body = ['\n\n'] self.body.append(CUSTOM_HACK_HTML) if not self.title: self.foot.insert(0, FOOTER) def visit_title(self, node): #self.context.append(self.TEXT_TO_HTML) if isinstance(node.parent, nodes.topic): self.body.append( self.starttag(node, 'P', '', CLASS='topic-title')) self.context.append('

\n') return #print self.sectionlevel, node.astext() bodystart = len(self.body) postcontext = self.TDOpen if self.sectionlevel == 0: self.titletext = node.astext() self.head.append('Psyco - %s\n' % self.encode(self.titletext)) self.body.append('\n') self.foot.insert(0, ''' ''') self.body.append( ''' ''') self.body.append(self.starttag(node, 'TR', '')) self.body.append( ''' ''') if self.title: self.body.append( ''' ''') if node.parent.findclass(nodes.subtitle) is None: postcontext += self.build_contents() #self.TEXT_TO_HTML = self.TEXT_TO_HTML_NBSP elif self.sectionlevel == 1: self.body.append(self.TDClose) self.body.append(self.starttag(node, 'TR', '')) self.body.append( ''' ''') else: self.body.append( self.starttag(node, 'H%s' % self.sectionlevel, '')) context = '' % self.sectionlevel postcontext = '' if node.hasattr('refid'): self.body.insert(bodystart, '' % node['refid']) context += '' self.context.append(context + postcontext) def depart_title(self, node): self.body.append(self.context.pop()) #self.TEXT_TO_HTML = self.context.pop() def visit_section(self, node): HTMLTranslatorBase.visit_section(self, node) self.body.append('\n\n') def depart_section(self, node): HTMLTranslatorBase.depart_section(self, node) assert self.body[-1] == '\n' del self.body[-1] def depart_document(self, node): pass def build_contents(self): result = ['

''')
                context = (
''' ''') else: self.body.append( '''

''') context = ( '''    

''') context += ( '''
    ''') context = ( '''
'] for key, title, url in CONTENTS: if title == self.titletext: text = '%s' % key else: text = '%s' % (url, key) result.append(' ' % text) result.append('
    %s    

') #result.append('
') return '\n'.join(result) def visit_subtitle(self, node): self.body.append('

' + ' '*14) context = '

' + self.build_contents() self.context.append(context) def depart_subtitle(self, node): self.body.append(self.context.pop())