From 29901ff5286c985c41b2b0760c5061f36ecd7840 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 9 Aug 1996 21:46:34 +0000 Subject: Some improvements by Fred Drake. --- Doc/texi2html.py | 118 ++++++++++++++++++++++----------------------- Doc/tools/texi2html.py | 118 ++++++++++++++++++++++----------------------- Tools/scripts/texi2html.py | 118 ++++++++++++++++++++++----------------------- 3 files changed, 174 insertions(+), 180 deletions(-) diff --git a/Doc/texi2html.py b/Doc/texi2html.py index a1c0ebd..5084284 100644 --- a/Doc/texi2html.py +++ b/Doc/texi2html.py @@ -74,8 +74,7 @@ class Node: self.cont = '' def write (self, *lines): - for line in lines: - self.lines.append (line) + map(self.lines.append, lines) def flush (self): fp = open (self.dirname + '/' + makefile(self.name), 'w') @@ -99,7 +98,7 @@ class Node: length = len (self.lines) self.text = string.joinfields (self.lines, '') self.lines = [] - self.write ('

\n') + self.write ('
\n') if self.cont != self.next: self.link('Cont', self.cont) self.link('Next', self.next) @@ -107,20 +106,19 @@ class Node: self.link('Up', self.up) if self.name <> self.topname: self.link('Top', self.topname) - self.write ('

\n') - links = string.joinfields (self.lines, '') + self.write ('


\n') + links = string.joinfields(self.lines, '') self.lines = [] - self.prologue = \ - '\n' + \ - '\n' + \ - '

\n\n' + \ - '' + self.title + '\n' + \ - '\n\n

\n' + \ - links + self.prologue = ('\n' + '\n' + '\n' + ' ' + self.title + '\n' + '\n' + \ + links) if length > 20: - self.epilogue = links + '\n' + self.epilogue = '

\n%s\n' % links else: self.epilogue = '\n' @@ -311,10 +309,10 @@ class TexinfoParser: if nodename[0] == ':': nodename = label else: nodename = line[e:f] punct = line[g:h] - self.write('

', nodename, \ - '', punct, '\n
') + self.write('
  • ', nodename, + '', punct, '\n') self.expand(line[end:]) else: text = string.joinfields(accu, '') @@ -577,8 +575,8 @@ class TexinfoParser: def open_dfn(self): self.write('') def close_dfn(self): self.write('') - def open_emph(self): self.write('') - def close_emph(self): self.write('') + def open_emph(self): self.write('') + def close_emph(self): self.write('') open_i = open_emph close_i = close_emph @@ -599,15 +597,16 @@ class TexinfoParser: # self.savetext = None def writefootnotes(self): - self.write('

    ---------- Footnotes ----------

    \n') + self.write('\n
    \n' + 'Footnotes\n

    ') for id, text in self.footnotes: self.write('(', \ id, ')\n', text, '

    \n') self.footnotes = [] - def open_file(self): self.write('') - def close_file(self): self.write('') + def open_file(self): self.write('') + def close_file(self): self.write('') def open_kbd(self): self.write('') def close_kbd(self): self.write('') @@ -836,18 +835,6 @@ class TexinfoParser: if not self.topname: self.topname = name title = name if self.title: title = title + ' -- ' + self.title - # No idea what this means, but this is what latex2html writes - # self.write('\n') - # self.write('\n') - # self.write ('

    \n\n') - # self.write('', title, '\n') - # self.write ('\n\n

    \n


    \n') - # self.link('Next', next) - # self.link('Prev', prev) - # self.link('Up', up) - # if self.nodename <> self.topname: - # self.link('Top', self.topname) - # self.write ('

    \n') self.node = Node (self.dirname, self.nodename, self.topname, \ title, next, prev, up) @@ -965,14 +952,26 @@ class TexinfoParser: do_summarycontents = do_shortcontents def listcontents(self, title, maxlevel): - self.write('

    ', title, '

    \n
      \n') + self.write('

      ', title, '

      \n\n') + if level > maxlevel: + continue + if level > prevlevels[-1]: + # can only advance one level at a time + self.write(' '*prevlevels[-1], '
        \n') + prevlevels.append(level) + elif level < prevlevels[-1]: + # might drop back multiple levels + while level < prevlevels[-1]: + del prevlevels[-1] + self.write(' '*prevlevels[-1], + '
      \n') + self.write(' '*level, '
    • ') + self.expand(title) + self.write('\n') + self.write('
    \n' * len(prevlevels)) # --- Page lay-out --- @@ -1229,14 +1228,14 @@ class TexinfoParser: # --- Enumerations, displays, quotations --- # XXX Most of these should increase the indentation somehow - def bgn_quotation(self, args): self.write('

    ') - def end_quotation(self): self.write('

    \n') + def bgn_quotation(self, args): self.write('

    ') + def end_quotation(self): self.write('
    \n') def bgn_example(self, args): self.nofill = self.nofill + 1 - self.write('
    ')
    +		self.write('
    ')
     	def end_example(self):
    -		self.write('
    ') + self.write('
    ') self.nofill = self.nofill - 1 bgn_lisp = bgn_example # Synonym when contents are executable lisp code @@ -1248,19 +1247,11 @@ class TexinfoParser: bgn_smalllisp = bgn_lisp # Ditto end_smalllisp = end_lisp - def bgn_display(self, args): - self.nofill = self.nofill + 1 - self.write('
    \n')
    -	def end_display(self):
    -		self.write('
    \n') - self.nofill = self.nofill - 1 + bgn_display = bgn_example + end_display = end_example - def bgn_format(self, args): - self.nofill = self.nofill + 1 - self.write('
    \n')
    -	def end_format(self):
    -		self.write('
    \n') - self.nofill = self.nofill - 1 + bgn_format = bgn_display + end_format = end_display def do_exdent(self, args): self.expand(args + '\n') # XXX Should really mess with indentation @@ -1279,8 +1270,10 @@ class TexinfoParser: self.write('\n') self.nofill = self.nofill - 1 - def bgn_menu(self, args): self.write('

    Menu

    \n') - def end_menu(self): self.write('
    \n') + def bgn_menu(self, args): + self.write('\n') + self.write(' Menu

    \n') + def end_menu(self): self.write('

    \n') def bgn_cartouche(self, args): pass def end_cartouche(self): pass @@ -1364,13 +1357,18 @@ class TexinfoParser: del index[:] index1.sort() self.write('
    \n') + prevkey = prevnode = None for sortkey, key, node in index1: + if (key, node) == (prevkey, prevnode): + continue if self.debugging > 1: print key, ':', node self.write('
    ') if iscodeindex: key = '@code{' + key + '}' - self.expand(key) + if key != prevkey: + self.expand(key) self.write('
    ', node, '\n') + prevkey, prevnode = key, node self.write('
    \n') # --- Final error reports --- diff --git a/Doc/tools/texi2html.py b/Doc/tools/texi2html.py index a1c0ebd..5084284 100644 --- a/Doc/tools/texi2html.py +++ b/Doc/tools/texi2html.py @@ -74,8 +74,7 @@ class Node: self.cont = '' def write (self, *lines): - for line in lines: - self.lines.append (line) + map(self.lines.append, lines) def flush (self): fp = open (self.dirname + '/' + makefile(self.name), 'w') @@ -99,7 +98,7 @@ class Node: length = len (self.lines) self.text = string.joinfields (self.lines, '') self.lines = [] - self.write ('

    \n') + self.write ('
    \n') if self.cont != self.next: self.link('Cont', self.cont) self.link('Next', self.next) @@ -107,20 +106,19 @@ class Node: self.link('Up', self.up) if self.name <> self.topname: self.link('Top', self.topname) - self.write ('

    \n') - links = string.joinfields (self.lines, '') + self.write ('


    \n') + links = string.joinfields(self.lines, '') self.lines = [] - self.prologue = \ - '\n' + \ - '\n' + \ - '

    \n\n' + \ - '' + self.title + '\n' + \ - '\n\n

    \n' + \ - links + self.prologue = ('\n' + '\n' + '\n' + ' ' + self.title + '\n' + '\n' + \ + links) if length > 20: - self.epilogue = links + '\n' + self.epilogue = '

    \n%s\n' % links else: self.epilogue = '\n' @@ -311,10 +309,10 @@ class TexinfoParser: if nodename[0] == ':': nodename = label else: nodename = line[e:f] punct = line[g:h] - self.write('

    ', nodename, \ - '', punct, '\n
    ') + self.write('
  • ', nodename, + '', punct, '\n') self.expand(line[end:]) else: text = string.joinfields(accu, '') @@ -577,8 +575,8 @@ class TexinfoParser: def open_dfn(self): self.write('') def close_dfn(self): self.write('') - def open_emph(self): self.write('') - def close_emph(self): self.write('') + def open_emph(self): self.write('') + def close_emph(self): self.write('') open_i = open_emph close_i = close_emph @@ -599,15 +597,16 @@ class TexinfoParser: # self.savetext = None def writefootnotes(self): - self.write('

    ---------- Footnotes ----------

    \n') + self.write('\n
    \n' + 'Footnotes\n

    ') for id, text in self.footnotes: self.write('(', \ id, ')\n', text, '

    \n') self.footnotes = [] - def open_file(self): self.write('') - def close_file(self): self.write('') + def open_file(self): self.write('') + def close_file(self): self.write('') def open_kbd(self): self.write('') def close_kbd(self): self.write('') @@ -836,18 +835,6 @@ class TexinfoParser: if not self.topname: self.topname = name title = name if self.title: title = title + ' -- ' + self.title - # No idea what this means, but this is what latex2html writes - # self.write('\n') - # self.write('\n') - # self.write ('

    \n\n') - # self.write('', title, '\n') - # self.write ('\n\n

    \n


    \n') - # self.link('Next', next) - # self.link('Prev', prev) - # self.link('Up', up) - # if self.nodename <> self.topname: - # self.link('Top', self.topname) - # self.write ('

    \n') self.node = Node (self.dirname, self.nodename, self.topname, \ title, next, prev, up) @@ -965,14 +952,26 @@ class TexinfoParser: do_summarycontents = do_shortcontents def listcontents(self, title, maxlevel): - self.write('

    ', title, '

    \n
      \n') + self.write('

      ', title, '

      \n\n') + if level > maxlevel: + continue + if level > prevlevels[-1]: + # can only advance one level at a time + self.write(' '*prevlevels[-1], '
        \n') + prevlevels.append(level) + elif level < prevlevels[-1]: + # might drop back multiple levels + while level < prevlevels[-1]: + del prevlevels[-1] + self.write(' '*prevlevels[-1], + '
      \n') + self.write(' '*level, '
    • ') + self.expand(title) + self.write('\n') + self.write('
    \n' * len(prevlevels)) # --- Page lay-out --- @@ -1229,14 +1228,14 @@ class TexinfoParser: # --- Enumerations, displays, quotations --- # XXX Most of these should increase the indentation somehow - def bgn_quotation(self, args): self.write('

    ') - def end_quotation(self): self.write('

    \n') + def bgn_quotation(self, args): self.write('

    ') + def end_quotation(self): self.write('
    \n') def bgn_example(self, args): self.nofill = self.nofill + 1 - self.write('
    ')
    +		self.write('
    ')
     	def end_example(self):
    -		self.write('
    ') + self.write('
    ') self.nofill = self.nofill - 1 bgn_lisp = bgn_example # Synonym when contents are executable lisp code @@ -1248,19 +1247,11 @@ class TexinfoParser: bgn_smalllisp = bgn_lisp # Ditto end_smalllisp = end_lisp - def bgn_display(self, args): - self.nofill = self.nofill + 1 - self.write('
    \n')
    -	def end_display(self):
    -		self.write('
    \n') - self.nofill = self.nofill - 1 + bgn_display = bgn_example + end_display = end_example - def bgn_format(self, args): - self.nofill = self.nofill + 1 - self.write('
    \n')
    -	def end_format(self):
    -		self.write('
    \n') - self.nofill = self.nofill - 1 + bgn_format = bgn_display + end_format = end_display def do_exdent(self, args): self.expand(args + '\n') # XXX Should really mess with indentation @@ -1279,8 +1270,10 @@ class TexinfoParser: self.write('\n') self.nofill = self.nofill - 1 - def bgn_menu(self, args): self.write('

    Menu

    \n') - def end_menu(self): self.write('
    \n') + def bgn_menu(self, args): + self.write('\n') + self.write(' Menu

    \n') + def end_menu(self): self.write('

    \n') def bgn_cartouche(self, args): pass def end_cartouche(self): pass @@ -1364,13 +1357,18 @@ class TexinfoParser: del index[:] index1.sort() self.write('
    \n') + prevkey = prevnode = None for sortkey, key, node in index1: + if (key, node) == (prevkey, prevnode): + continue if self.debugging > 1: print key, ':', node self.write('
    ') if iscodeindex: key = '@code{' + key + '}' - self.expand(key) + if key != prevkey: + self.expand(key) self.write('
    ', node, '\n') + prevkey, prevnode = key, node self.write('
    \n') # --- Final error reports --- diff --git a/Tools/scripts/texi2html.py b/Tools/scripts/texi2html.py index a1c0ebd..5084284 100755 --- a/Tools/scripts/texi2html.py +++ b/Tools/scripts/texi2html.py @@ -74,8 +74,7 @@ class Node: self.cont = '' def write (self, *lines): - for line in lines: - self.lines.append (line) + map(self.lines.append, lines) def flush (self): fp = open (self.dirname + '/' + makefile(self.name), 'w') @@ -99,7 +98,7 @@ class Node: length = len (self.lines) self.text = string.joinfields (self.lines, '') self.lines = [] - self.write ('

    \n') + self.write ('
    \n') if self.cont != self.next: self.link('Cont', self.cont) self.link('Next', self.next) @@ -107,20 +106,19 @@ class Node: self.link('Up', self.up) if self.name <> self.topname: self.link('Top', self.topname) - self.write ('

    \n') - links = string.joinfields (self.lines, '') + self.write ('


    \n') + links = string.joinfields(self.lines, '') self.lines = [] - self.prologue = \ - '\n' + \ - '\n' + \ - '

    \n\n' + \ - '' + self.title + '\n' + \ - '\n\n

    \n' + \ - links + self.prologue = ('\n' + '\n' + '\n' + ' ' + self.title + '\n' + '\n' + \ + links) if length > 20: - self.epilogue = links + '\n' + self.epilogue = '

    \n%s\n' % links else: self.epilogue = '\n' @@ -311,10 +309,10 @@ class TexinfoParser: if nodename[0] == ':': nodename = label else: nodename = line[e:f] punct = line[g:h] - self.write('

    ', nodename, \ - '', punct, '\n
    ') + self.write('
  • ', nodename, + '', punct, '\n') self.expand(line[end:]) else: text = string.joinfields(accu, '') @@ -577,8 +575,8 @@ class TexinfoParser: def open_dfn(self): self.write('') def close_dfn(self): self.write('') - def open_emph(self): self.write('') - def close_emph(self): self.write('') + def open_emph(self): self.write('') + def close_emph(self): self.write('') open_i = open_emph close_i = close_emph @@ -599,15 +597,16 @@ class TexinfoParser: # self.savetext = None def writefootnotes(self): - self.write('

    ---------- Footnotes ----------

    \n') + self.write('\n
    \n' + 'Footnotes\n

    ') for id, text in self.footnotes: self.write('(', \ id, ')\n', text, '

    \n') self.footnotes = [] - def open_file(self): self.write('') - def close_file(self): self.write('') + def open_file(self): self.write('') + def close_file(self): self.write('') def open_kbd(self): self.write('') def close_kbd(self): self.write('') @@ -836,18 +835,6 @@ class TexinfoParser: if not self.topname: self.topname = name title = name if self.title: title = title + ' -- ' + self.title - # No idea what this means, but this is what latex2html writes - # self.write('\n') - # self.write('\n') - # self.write ('

    \n\n') - # self.write('', title, '\n') - # self.write ('\n\n

    \n


    \n') - # self.link('Next', next) - # self.link('Prev', prev) - # self.link('Up', up) - # if self.nodename <> self.topname: - # self.link('Top', self.topname) - # self.write ('

    \n') self.node = Node (self.dirname, self.nodename, self.topname, \ title, next, prev, up) @@ -965,14 +952,26 @@ class TexinfoParser: do_summarycontents = do_shortcontents def listcontents(self, title, maxlevel): - self.write('

    ', title, '

    \n
      \n') + self.write('

      ', title, '

      \n\n') + if level > maxlevel: + continue + if level > prevlevels[-1]: + # can only advance one level at a time + self.write(' '*prevlevels[-1], '
        \n') + prevlevels.append(level) + elif level < prevlevels[-1]: + # might drop back multiple levels + while level < prevlevels[-1]: + del prevlevels[-1] + self.write(' '*prevlevels[-1], + '
      \n') + self.write(' '*level, '
    • ') + self.expand(title) + self.write('\n') + self.write('
    \n' * len(prevlevels)) # --- Page lay-out --- @@ -1229,14 +1228,14 @@ class TexinfoParser: # --- Enumerations, displays, quotations --- # XXX Most of these should increase the indentation somehow - def bgn_quotation(self, args): self.write('

    ') - def end_quotation(self): self.write('

    \n') + def bgn_quotation(self, args): self.write('

    ') + def end_quotation(self): self.write('
    \n') def bgn_example(self, args): self.nofill = self.nofill + 1 - self.write('
    ')
    +		self.write('
    ')
     	def end_example(self):
    -		self.write('
    ') + self.write('
    ') self.nofill = self.nofill - 1 bgn_lisp = bgn_example # Synonym when contents are executable lisp code @@ -1248,19 +1247,11 @@ class TexinfoParser: bgn_smalllisp = bgn_lisp # Ditto end_smalllisp = end_lisp - def bgn_display(self, args): - self.nofill = self.nofill + 1 - self.write('
    \n')
    -	def end_display(self):
    -		self.write('
    \n') - self.nofill = self.nofill - 1 + bgn_display = bgn_example + end_display = end_example - def bgn_format(self, args): - self.nofill = self.nofill + 1 - self.write('
    \n')
    -	def end_format(self):
    -		self.write('
    \n') - self.nofill = self.nofill - 1 + bgn_format = bgn_display + end_format = end_display def do_exdent(self, args): self.expand(args + '\n') # XXX Should really mess with indentation @@ -1279,8 +1270,10 @@ class TexinfoParser: self.write('\n') self.nofill = self.nofill - 1 - def bgn_menu(self, args): self.write('

    Menu

    \n') - def end_menu(self): self.write('
    \n') + def bgn_menu(self, args): + self.write('\n') + self.write(' Menu

    \n') + def end_menu(self): self.write('

    \n') def bgn_cartouche(self, args): pass def end_cartouche(self): pass @@ -1364,13 +1357,18 @@ class TexinfoParser: del index[:] index1.sort() self.write('
    \n') + prevkey = prevnode = None for sortkey, key, node in index1: + if (key, node) == (prevkey, prevnode): + continue if self.debugging > 1: print key, ':', node self.write('
    ') if iscodeindex: key = '@code{' + key + '}' - self.expand(key) + if key != prevkey: + self.expand(key) self.write('
    ', node, '\n') + prevkey, prevnode = key, node self.write('
    \n') # --- Final error reports --- -- cgit v0.12