# Author: Gunnar Schwant # Contact: g.schwant@gmx.de # Revision: $Revision: 1424 $ # Date: $Date: 2003-06-11 22:15:41 +0200 (Mi, 11. Jun 2003) $ # Copyright: This module has been placed in the public domain. from docutils import writers, nodes, languages import docutils, html4css1, os class Writer(html4css1.Writer): def __init__(self): writers.Writer.__init__(self) self.translator_class = HTMLTranslator class HTMLTranslator(html4css1.HTMLTranslator): def __init__(self, document): html4css1.HTMLTranslator.__init__(self, document) self.navigation_bgcolor = '#FFFFFF' self.body_prefix = [self.get_body_prefix()] self.body_suffix = [self.get_body_suffix()] def get_body_prefix(self): navtop = os.path.join(os.path.split(self.settings._destination)[0], 'top.nav') navright = os.path.join(os.path.split(self.settings._destination)[0], 'right.nav') if os.path.exists(navright): colspan = 3 width = '70%' else: colspan = 2 width = '85%' navleft = '%s%s' % (os.path.splitext(self.settings._destination)[0], '.nav') bgcolor = color1 = color2 = self.navigation_bgcolor cornerpic = None if not os.path.exists(navleft): navleft = os.path.join(os.path.split(self.settings._destination)[0], 'left.nav') if os.path.exists(navleft): if os.path.exists(navtop): f = open(navtop, 'rt') lines = f.readlines() f.close() for line in lines: val = line.split('|') for i in range(len(val)): val[i] = val[i].strip() if val[0] == 'color': bgcolor = color1 = color2 = val[1] self.navigation_bgcolor = bgcolor if val[0] == 'cornerpic': cornerpic = val[1] body_prefix = '\n\n\n' if os.path.exists(navtop): body_prefix = body_prefix + '\n' \ '' % body_prefix f = open(navleft, 'rt') lines = f.readlines() f.close() body_prefix = '%s\n\n\n\n' \ % (body_suffix, color2, val[2], val[1]) elif val[0] == 'colors': (color1, color2) = (val[1], val[2]) elif val[0] == 'section': body_suffix = '%s\n' \ % (body_suffix, val[1]) else: body_suffix = '%s%s' % (body_suffix, val[1]) elif val[0] == 'raw': body_suffix = '%s\n' \ % (body_suffix, color2, val[1]) body_suffix = '%s\n
  ' % (body_prefix, bgcolor, bgcolor, colspan) body_prefix = body_prefix + '\n' body_prefix = '%s\n' % body_prefix for line in lines: val = line.split('|') for i in range(len(val)): val[i] = val[i].strip() if val[0] == 'link': body_prefix = '%s\n' \ % (body_prefix, val[2], val[1]) elif val[0] == 'raw': body_prefix = '%s\n' \ % (body_prefix, val[1]) body_prefix = '%s\n
  ' \ % (body_prefix, width) else: body_prefix = '\n\n' return body_prefix def get_body_suffix(self): bgcolor = color1 = color2 = self.navigation_bgcolor navleft = '%s%s' % (os.path.splitext(self.settings._destination)[0], '.nav') if not os.path.exists(navleft): navleft = os.path.join(os.path.split(self.settings._destination)[0], 'left.nav') navright = os.path.join(os.path.split(self.settings._destination)[0], 'right.nav') if os.path.exists(navleft) and os.path.exists(navright): f = open(navright, 'rt') lines = f.readlines() f.close() body_suffix = '  
 %s
 ' \ % (body_suffix, color1) if color1 != bgcolor: body_suffix = '%s%s' \ '
 %s
\n\n\n' \ '\n' % body_suffix elif os.path.exists(navleft): body_suffix = '\n\n\n' else: body_suffix = '\n\n' return body_suffix