Barry Warsaw | 6a508ae | 1998-04-23 22:59:33 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 2 | |
| 3 | # Convert GNU texinfo files into HTML, one file per node. |
| 4 | # Based on Texinfo 2.14. |
Guido van Rossum | 06f4289 | 1995-08-28 03:01:00 +0000 | [diff] [blame] | 5 | # Usage: texi2html [-d] [-d] [-c] inputfile outputdirectory |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 6 | # The input file must be a complete texinfo file, e.g. emacs.texi. |
| 7 | # This creates many files (one per info node) in the output directory, |
| 8 | # overwriting existing files of the same name. All files created have |
| 9 | # ".html" as their extension. |
| 10 | |
| 11 | |
| 12 | # XXX To do: |
| 13 | # - handle @comment*** correctly |
| 14 | # - handle @xref {some words} correctly |
| 15 | # - handle @ftable correctly (items aren't indexed?) |
| 16 | # - handle @itemx properly |
| 17 | # - handle @exdent properly |
| 18 | # - add links directly to the proper line from indices |
| 19 | # - check against the definitive list of @-cmds; we still miss (among others): |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 20 | # - @defindex (hard) |
| 21 | # - @c(omment) in the middle of a line (rarely used) |
| 22 | # - @this* (not really needed, only used in headers anyway) |
| 23 | # - @today{} (ever used outside title page?) |
| 24 | |
Guido van Rossum | 06f4289 | 1995-08-28 03:01:00 +0000 | [diff] [blame] | 25 | # More consistent handling of chapters/sections/etc. |
| 26 | # Lots of documentation |
| 27 | # Many more options: |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 28 | # -top designate top node |
| 29 | # -links customize which types of links are included |
| 30 | # -split split at chapters or sections instead of nodes |
| 31 | # -name Allow different types of filename handling. Non unix systems |
| 32 | # will have problems with long node names |
| 33 | # ... |
Guido van Rossum | 06f4289 | 1995-08-28 03:01:00 +0000 | [diff] [blame] | 34 | # Support the most recent texinfo version and take a good look at HTML 3.0 |
| 35 | # More debugging output (customizable) and more fexible error handling |
| 36 | # How about icons ? |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 37 | |
| 38 | import os |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 39 | import string |
Barry Warsaw | 6a508ae | 1998-04-23 22:59:33 +0000 | [diff] [blame] | 40 | import re |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 41 | |
| 42 | MAGIC = '\\input texinfo' |
| 43 | |
Barry Warsaw | 6a508ae | 1998-04-23 22:59:33 +0000 | [diff] [blame] | 44 | cmprog = re.compile('^@([a-z]+)([ \t]|$)') # Command (line-oriented) |
| 45 | blprog = re.compile('^[ \t]*$') # Blank line |
| 46 | kwprog = re.compile('@[a-z]+') # Keyword (embedded, usually |
| 47 | # with {} args) |
| 48 | spprog = re.compile('[\n@{}&<>]') # Special characters in |
Tim Peters | 70c4378 | 2001-01-17 08:48:39 +0000 | [diff] [blame] | 49 | # running text |
Barry Warsaw | 6a508ae | 1998-04-23 22:59:33 +0000 | [diff] [blame] | 50 | # |
| 51 | # menu item (Yuck!) |
| 52 | miprog = re.compile('^\* ([^:]*):(:|[ \t]*([^\t,\n.]+)([^ \t\n]*))[ \t\n]*') |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 53 | |
Guido van Rossum | 06f4289 | 1995-08-28 03:01:00 +0000 | [diff] [blame] | 54 | |
Tim Peters | 70c4378 | 2001-01-17 08:48:39 +0000 | [diff] [blame] | 55 | |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 56 | class HTMLNode: |
| 57 | """Some of the parser's functionality is separated into this class. |
Guido van Rossum | 06f4289 | 1995-08-28 03:01:00 +0000 | [diff] [blame] | 58 | |
| 59 | A Node accumulates its contents, takes care of links to other Nodes |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 60 | and saves itself when it is finished and all links are resolved. |
| 61 | """ |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 62 | |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 63 | DOCTYPE = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">' |
| 64 | |
| 65 | type = 0 |
| 66 | cont = '' |
| 67 | epilogue = '</BODY></HTML>\n' |
| 68 | |
| 69 | def __init__(self, dir, name, topname, title, next, prev, up): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 70 | self.dirname = dir |
| 71 | self.name = name |
| 72 | if topname: |
| 73 | self.topname = topname |
| 74 | else: |
| 75 | self.topname = name |
| 76 | self.title = title |
| 77 | self.next = next |
| 78 | self.prev = prev |
| 79 | self.up = up |
| 80 | self.lines = [] |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 81 | |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 82 | def write(self, *lines): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 83 | map(self.lines.append, lines) |
Guido van Rossum | 06f4289 | 1995-08-28 03:01:00 +0000 | [diff] [blame] | 84 | |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 85 | def flush(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 86 | fp = open(self.dirname + '/' + makefile(self.name), 'w') |
| 87 | fp.write(self.prologue) |
| 88 | fp.write(self.text) |
| 89 | fp.write(self.epilogue) |
| 90 | fp.close() |
Guido van Rossum | 06f4289 | 1995-08-28 03:01:00 +0000 | [diff] [blame] | 91 | |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 92 | def link(self, label, nodename, rel=None, rev=None): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 93 | if nodename: |
| 94 | if string.lower(nodename) == '(dir)': |
| 95 | addr = '../dir.html' |
| 96 | title = '' |
| 97 | else: |
| 98 | addr = makefile(nodename) |
| 99 | title = ' TITLE="%s"' % nodename |
| 100 | self.write(label, ': <A HREF="', addr, '"', \ |
| 101 | rel and (' REL=' + rel) or "", \ |
| 102 | rev and (' REV=' + rev) or "", \ |
| 103 | title, '>', nodename, '</A> \n') |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 104 | |
Guido van Rossum | 06f4289 | 1995-08-28 03:01:00 +0000 | [diff] [blame] | 105 | def finalize(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 106 | length = len(self.lines) |
| 107 | self.text = string.joinfields(self.lines, '') |
| 108 | self.lines = [] |
| 109 | self.open_links() |
| 110 | self.output_links() |
| 111 | self.close_links() |
| 112 | links = string.joinfields(self.lines, '') |
| 113 | self.lines = [] |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 114 | |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 115 | self.prologue = ( |
| 116 | self.DOCTYPE + |
| 117 | '\n<HTML><HEAD>\n' |
| 118 | ' <!-- Converted with texi2html and Python -->\n' |
| 119 | ' <TITLE>' + self.title + '</TITLE>\n' |
| 120 | ' <LINK REL=Next HREF="' |
| 121 | + makefile(self.next) + '" TITLE="' + self.next + '">\n' |
| 122 | ' <LINK REL=Previous HREF="' |
| 123 | + makefile(self.prev) + '" TITLE="' + self.prev + '">\n' |
| 124 | ' <LINK REL=Up HREF="' |
| 125 | + makefile(self.up) + '" TITLE="' + self.up + '">\n' |
| 126 | '</HEAD><BODY>\n' + |
| 127 | links) |
| 128 | if length > 20: |
| 129 | self.epilogue = '<P>\n%s</BODY></HTML>\n' % links |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 130 | |
| 131 | def open_links(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 132 | self.write('<HR>\n') |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 133 | |
| 134 | def close_links(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 135 | self.write('<HR>\n') |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 136 | |
| 137 | def output_links(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 138 | if self.cont != self.next: |
| 139 | self.link(' Cont', self.cont) |
| 140 | self.link(' Next', self.next, rel='Next') |
| 141 | self.link(' Prev', self.prev, rel='Previous') |
| 142 | self.link(' Up', self.up, rel='Up') |
| 143 | if self.name <> self.topname: |
| 144 | self.link(' Top', self.topname) |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 145 | |
| 146 | |
| 147 | class HTML3Node(HTMLNode): |
| 148 | |
| 149 | DOCTYPE = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML Level 3//EN//3.0">' |
| 150 | |
| 151 | def open_links(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 152 | self.write('<DIV CLASS=Navigation>\n <HR>\n') |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 153 | |
| 154 | def close_links(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 155 | self.write(' <HR>\n</DIV>\n') |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 156 | |
Guido van Rossum | 06f4289 | 1995-08-28 03:01:00 +0000 | [diff] [blame] | 157 | |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 158 | class TexinfoParser: |
| 159 | |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 160 | COPYRIGHT_SYMBOL = "©" |
| 161 | FN_ID_PATTERN = "(%(id)s)" |
| 162 | FN_SOURCE_PATTERN = '<A NAME=footnoteref%(id)s' \ |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 163 | ' HREF="#footnotetext%(id)s">' \ |
| 164 | + FN_ID_PATTERN + '</A>' |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 165 | FN_TARGET_PATTERN = '<A NAME=footnotetext%(id)s' \ |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 166 | ' HREF="#footnoteref%(id)s">' \ |
| 167 | + FN_ID_PATTERN + '</A>\n%(text)s<P>\n' |
Fred Drake | 22f7f9e | 1996-10-11 16:54:00 +0000 | [diff] [blame] | 168 | FN_HEADER = '\n<P>\n<HR NOSHADE SIZE=1 WIDTH=200>\n' \ |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 169 | '<STRONG><EM>Footnotes</EM></STRONG>\n<P>' |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 170 | |
| 171 | |
| 172 | Node = HTMLNode |
| 173 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 174 | # Initialize an instance |
| 175 | def __init__(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 176 | self.unknown = {} # statistics about unknown @-commands |
| 177 | self.filenames = {} # Check for identical filenames |
| 178 | self.debugging = 0 # larger values produce more output |
| 179 | self.print_headers = 0 # always print headers? |
| 180 | self.nodefp = None # open file we're writing to |
| 181 | self.nodelineno = 0 # Linenumber relative to node |
| 182 | self.links = None # Links from current node |
| 183 | self.savetext = None # If not None, save text head instead |
| 184 | self.savestack = [] # If not None, save text head instead |
| 185 | self.dirname = 'tmp' # directory where files are created |
| 186 | self.includedir = '.' # directory to search @include files |
| 187 | self.nodename = '' # name of current node |
| 188 | self.topname = '' # name of top node (first node seen) |
| 189 | self.title = '' # title of this whole Texinfo tree |
| 190 | self.resetindex() # Reset all indices |
| 191 | self.contents = [] # Reset table of contents |
| 192 | self.numbering = [] # Reset section numbering counters |
| 193 | self.nofill = 0 # Normal operation: fill paragraphs |
| 194 | self.values={'html': 1} # Names that should be parsed in ifset |
| 195 | self.stackinfo={} # Keep track of state in the stack |
| 196 | # XXX The following should be reset per node?! |
| 197 | self.footnotes = [] # Reset list of footnotes |
| 198 | self.itemarg = None # Reset command used by @item |
| 199 | self.itemnumber = None # Reset number for @item in @enumerate |
| 200 | self.itemindex = None # Reset item index name |
| 201 | self.node = None |
| 202 | self.nodestack = [] |
| 203 | self.cont = 0 |
| 204 | self.includedepth = 0 |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 205 | # Set (output) directory name |
| 206 | def setdirname(self, dirname): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 207 | self.dirname = dirname |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 208 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 209 | # Set include directory name |
| 210 | def setincludedir(self, includedir): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 211 | self.includedir = includedir |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 212 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 213 | # Parse the contents of an entire file |
| 214 | def parse(self, fp): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 215 | line = fp.readline() |
| 216 | lineno = 1 |
| 217 | while line and (line[0] == '%' or blprog.match(line)): |
| 218 | line = fp.readline() |
| 219 | lineno = lineno + 1 |
| 220 | if line[:len(MAGIC)] <> MAGIC: |
| 221 | raise SyntaxError, 'file does not begin with '+`MAGIC` |
| 222 | self.parserest(fp, lineno) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 223 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 224 | # Parse the contents of a file, not expecting a MAGIC header |
| 225 | def parserest(self, fp, initial_lineno): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 226 | lineno = initial_lineno |
| 227 | self.done = 0 |
| 228 | self.skip = 0 |
| 229 | self.stack = [] |
| 230 | accu = [] |
| 231 | while not self.done: |
| 232 | line = fp.readline() |
| 233 | self.nodelineno = self.nodelineno + 1 |
| 234 | if not line: |
| 235 | if accu: |
| 236 | if not self.skip: self.process(accu) |
| 237 | accu = [] |
| 238 | if initial_lineno > 0: |
| 239 | print '*** EOF before @bye' |
| 240 | break |
| 241 | lineno = lineno + 1 |
Barry Warsaw | 6a508ae | 1998-04-23 22:59:33 +0000 | [diff] [blame] | 242 | mo = cmprog.match(line) |
| 243 | if mo: |
| 244 | a, b = mo.span(1) |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 245 | cmd = line[a:b] |
| 246 | if cmd in ('noindent', 'refill'): |
| 247 | accu.append(line) |
| 248 | else: |
| 249 | if accu: |
| 250 | if not self.skip: |
| 251 | self.process(accu) |
| 252 | accu = [] |
| 253 | self.command(line, mo) |
| 254 | elif blprog.match(line) and \ |
| 255 | 'format' not in self.stack and \ |
| 256 | 'example' not in self.stack: |
| 257 | if accu: |
| 258 | if not self.skip: |
| 259 | self.process(accu) |
| 260 | if self.nofill: |
| 261 | self.write('\n') |
| 262 | else: |
| 263 | self.write('<P>\n') |
| 264 | accu = [] |
| 265 | else: |
| 266 | # Append the line including trailing \n! |
| 267 | accu.append(line) |
| 268 | # |
| 269 | if self.skip: |
| 270 | print '*** Still skipping at the end' |
| 271 | if self.stack: |
| 272 | print '*** Stack not empty at the end' |
| 273 | print '***', self.stack |
| 274 | if self.includedepth == 0: |
| 275 | while self.nodestack: |
| 276 | self.nodestack[-1].finalize() |
| 277 | self.nodestack[-1].flush() |
| 278 | del self.nodestack[-1] |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 279 | |
| 280 | # Start saving text in a buffer instead of writing it to a file |
| 281 | def startsaving(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 282 | if self.savetext <> None: |
| 283 | self.savestack.append(self.savetext) |
| 284 | # print '*** Recursively saving text, expect trouble' |
| 285 | self.savetext = '' |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 286 | |
| 287 | # Return the text saved so far and start writing to file again |
| 288 | def collectsavings(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 289 | savetext = self.savetext |
| 290 | if len(self.savestack) > 0: |
| 291 | self.savetext = self.savestack[-1] |
| 292 | del self.savestack[-1] |
| 293 | else: |
| 294 | self.savetext = None |
| 295 | return savetext or '' |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 296 | |
| 297 | # Write text to file, or save it in a buffer, or ignore it |
| 298 | def write(self, *args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 299 | try: |
| 300 | text = string.joinfields(args, '') |
| 301 | except: |
| 302 | print args |
| 303 | raise TypeError |
| 304 | if self.savetext <> None: |
| 305 | self.savetext = self.savetext + text |
| 306 | elif self.nodefp: |
| 307 | self.nodefp.write(text) |
| 308 | elif self.node: |
| 309 | self.node.write(text) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 310 | # Complete the current node -- write footnotes and close file |
| 311 | def endnode(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 312 | if self.savetext <> None: |
| 313 | print '*** Still saving text at end of node' |
| 314 | dummy = self.collectsavings() |
| 315 | if self.footnotes: |
| 316 | self.writefootnotes() |
| 317 | if self.nodefp: |
| 318 | if self.nodelineno > 20: |
| 319 | self.write('<HR>\n') |
| 320 | [name, next, prev, up] = self.nodelinks[:4] |
| 321 | self.link('Next', next) |
| 322 | self.link('Prev', prev) |
| 323 | self.link('Up', up) |
| 324 | if self.nodename <> self.topname: |
| 325 | self.link('Top', self.topname) |
| 326 | self.write('<HR>\n') |
| 327 | self.write('</BODY>\n') |
| 328 | self.nodefp.close() |
| 329 | self.nodefp = None |
| 330 | elif self.node: |
| 331 | if not self.cont and \ |
| 332 | (not self.node.type or \ |
| 333 | (self.node.next and self.node.prev and self.node.up)): |
| 334 | self.node.finalize() |
| 335 | self.node.flush() |
| 336 | else: |
| 337 | self.nodestack.append(self.node) |
| 338 | self.node = None |
| 339 | self.nodename = '' |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 340 | |
| 341 | # Process a list of lines, expanding embedded @-commands |
| 342 | # This mostly distinguishes between menus and normal text |
| 343 | def process(self, accu): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 344 | if self.debugging > 1: |
| 345 | print self.skip, self.stack, |
| 346 | if accu: print accu[0][:30], |
| 347 | if accu[0][30:] or accu[1:]: print '...', |
| 348 | print |
| 349 | if self.stack and self.stack[-1] == 'menu': |
| 350 | # XXX should be done differently |
| 351 | for line in accu: |
Barry Warsaw | 6a508ae | 1998-04-23 22:59:33 +0000 | [diff] [blame] | 352 | mo = miprog.match(line) |
| 353 | if not mo: |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 354 | line = string.strip(line) + '\n' |
| 355 | self.expand(line) |
| 356 | continue |
Barry Warsaw | 6a508ae | 1998-04-23 22:59:33 +0000 | [diff] [blame] | 357 | bgn, end = mo.span(0) |
| 358 | a, b = mo.span(1) |
| 359 | c, d = mo.span(2) |
| 360 | e, f = mo.span(3) |
| 361 | g, h = mo.span(4) |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 362 | label = line[a:b] |
| 363 | nodename = line[c:d] |
| 364 | if nodename[0] == ':': nodename = label |
| 365 | else: nodename = line[e:f] |
| 366 | punct = line[g:h] |
| 367 | self.write(' <LI><A HREF="', |
| 368 | makefile(nodename), |
| 369 | '">', nodename, |
| 370 | '</A>', punct, '\n') |
| 371 | self.expand(line[end:]) |
| 372 | else: |
| 373 | text = string.joinfields(accu, '') |
| 374 | self.expand(text) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 375 | |
| 376 | # Write a string, expanding embedded @-commands |
| 377 | def expand(self, text): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 378 | stack = [] |
| 379 | i = 0 |
| 380 | n = len(text) |
| 381 | while i < n: |
| 382 | start = i |
Barry Warsaw | 6a508ae | 1998-04-23 22:59:33 +0000 | [diff] [blame] | 383 | mo = spprog.search(text, i) |
| 384 | if mo: |
| 385 | i = mo.start() |
| 386 | else: |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 387 | self.write(text[start:]) |
| 388 | break |
| 389 | self.write(text[start:i]) |
| 390 | c = text[i] |
| 391 | i = i+1 |
| 392 | if c == '\n': |
| 393 | self.write('\n') |
| 394 | continue |
| 395 | if c == '<': |
| 396 | self.write('<') |
| 397 | continue |
| 398 | if c == '>': |
| 399 | self.write('>') |
| 400 | continue |
| 401 | if c == '&': |
| 402 | self.write('&') |
| 403 | continue |
| 404 | if c == '{': |
| 405 | stack.append('') |
| 406 | continue |
| 407 | if c == '}': |
| 408 | if not stack: |
| 409 | print '*** Unmatched }' |
| 410 | self.write('}') |
| 411 | continue |
| 412 | cmd = stack[-1] |
| 413 | del stack[-1] |
| 414 | try: |
| 415 | method = getattr(self, 'close_' + cmd) |
| 416 | except AttributeError: |
| 417 | self.unknown_close(cmd) |
| 418 | continue |
| 419 | method() |
| 420 | continue |
| 421 | if c <> '@': |
| 422 | # Cannot happen unless spprog is changed |
| 423 | raise RuntimeError, 'unexpected funny '+`c` |
| 424 | start = i |
Fred Drake | 79e75e1 | 2001-07-20 19:05:50 +0000 | [diff] [blame] | 425 | while i < n and text[i] in string.ascii_letters: i = i+1 |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 426 | if i == start: |
| 427 | # @ plus non-letter: literal next character |
| 428 | i = i+1 |
| 429 | c = text[start:i] |
| 430 | if c == ':': |
| 431 | # `@:' means no extra space after |
| 432 | # preceding `.', `?', `!' or `:' |
| 433 | pass |
| 434 | else: |
| 435 | # `@.' means a sentence-ending period; |
| 436 | # `@@', `@{', `@}' quote `@', `{', `}' |
| 437 | self.write(c) |
| 438 | continue |
| 439 | cmd = text[start:i] |
| 440 | if i < n and text[i] == '{': |
| 441 | i = i+1 |
| 442 | stack.append(cmd) |
| 443 | try: |
| 444 | method = getattr(self, 'open_' + cmd) |
| 445 | except AttributeError: |
| 446 | self.unknown_open(cmd) |
| 447 | continue |
| 448 | method() |
| 449 | continue |
| 450 | try: |
| 451 | method = getattr(self, 'handle_' + cmd) |
| 452 | except AttributeError: |
| 453 | self.unknown_handle(cmd) |
| 454 | continue |
| 455 | method() |
| 456 | if stack: |
| 457 | print '*** Stack not empty at para:', stack |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 458 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 459 | # --- Handle unknown embedded @-commands --- |
| 460 | |
| 461 | def unknown_open(self, cmd): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 462 | print '*** No open func for @' + cmd + '{...}' |
| 463 | cmd = cmd + '{' |
| 464 | self.write('@', cmd) |
| 465 | if not self.unknown.has_key(cmd): |
| 466 | self.unknown[cmd] = 1 |
| 467 | else: |
| 468 | self.unknown[cmd] = self.unknown[cmd] + 1 |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 469 | |
| 470 | def unknown_close(self, cmd): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 471 | print '*** No close func for @' + cmd + '{...}' |
| 472 | cmd = '}' + cmd |
| 473 | self.write('}') |
| 474 | if not self.unknown.has_key(cmd): |
| 475 | self.unknown[cmd] = 1 |
| 476 | else: |
| 477 | self.unknown[cmd] = self.unknown[cmd] + 1 |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 478 | |
| 479 | def unknown_handle(self, cmd): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 480 | print '*** No handler for @' + cmd |
| 481 | self.write('@', cmd) |
| 482 | if not self.unknown.has_key(cmd): |
| 483 | self.unknown[cmd] = 1 |
| 484 | else: |
| 485 | self.unknown[cmd] = self.unknown[cmd] + 1 |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 486 | |
| 487 | # XXX The following sections should be ordered as the texinfo docs |
| 488 | |
| 489 | # --- Embedded @-commands without {} argument list -- |
| 490 | |
| 491 | def handle_noindent(self): pass |
| 492 | |
| 493 | def handle_refill(self): pass |
| 494 | |
| 495 | # --- Include file handling --- |
| 496 | |
| 497 | def do_include(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 498 | file = args |
| 499 | file = os.path.join(self.includedir, file) |
| 500 | try: |
| 501 | fp = open(file, 'r') |
| 502 | except IOError, msg: |
| 503 | print '*** Can\'t open include file', `file` |
| 504 | return |
| 505 | if self.debugging: |
| 506 | print '--> file', `file` |
| 507 | save_done = self.done |
| 508 | save_skip = self.skip |
| 509 | save_stack = self.stack |
| 510 | self.includedepth = self.includedepth + 1 |
| 511 | self.parserest(fp, 0) |
| 512 | self.includedepth = self.includedepth - 1 |
| 513 | fp.close() |
| 514 | self.done = save_done |
| 515 | self.skip = save_skip |
| 516 | self.stack = save_stack |
| 517 | if self.debugging: |
| 518 | print '<-- file', `file` |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 519 | |
| 520 | # --- Special Insertions --- |
| 521 | |
| 522 | def open_dmn(self): pass |
| 523 | def close_dmn(self): pass |
| 524 | |
| 525 | def open_dots(self): self.write('...') |
| 526 | def close_dots(self): pass |
| 527 | |
| 528 | def open_bullet(self): pass |
| 529 | def close_bullet(self): pass |
| 530 | |
| 531 | def open_TeX(self): self.write('TeX') |
| 532 | def close_TeX(self): pass |
| 533 | |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 534 | def handle_copyright(self): self.write(self.COPYRIGHT_SYMBOL) |
| 535 | def open_copyright(self): self.write(self.COPYRIGHT_SYMBOL) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 536 | def close_copyright(self): pass |
| 537 | |
| 538 | def open_minus(self): self.write('-') |
| 539 | def close_minus(self): pass |
| 540 | |
| 541 | # --- Special Glyphs for Examples --- |
| 542 | |
| 543 | def open_result(self): self.write('=>') |
| 544 | def close_result(self): pass |
| 545 | |
| 546 | def open_expansion(self): self.write('==>') |
| 547 | def close_expansion(self): pass |
| 548 | |
| 549 | def open_print(self): self.write('-|') |
| 550 | def close_print(self): pass |
| 551 | |
| 552 | def open_error(self): self.write('error-->') |
| 553 | def close_error(self): pass |
| 554 | |
| 555 | def open_equiv(self): self.write('==') |
| 556 | def close_equiv(self): pass |
| 557 | |
| 558 | def open_point(self): self.write('-!-') |
| 559 | def close_point(self): pass |
| 560 | |
| 561 | # --- Cross References --- |
| 562 | |
| 563 | def open_pxref(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 564 | self.write('see ') |
| 565 | self.startsaving() |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 566 | def close_pxref(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 567 | self.makeref() |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 568 | |
| 569 | def open_xref(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 570 | self.write('See ') |
| 571 | self.startsaving() |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 572 | def close_xref(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 573 | self.makeref() |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 574 | |
| 575 | def open_ref(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 576 | self.startsaving() |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 577 | def close_ref(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 578 | self.makeref() |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 579 | |
| 580 | def open_inforef(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 581 | self.write('See info file ') |
| 582 | self.startsaving() |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 583 | def close_inforef(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 584 | text = self.collectsavings() |
| 585 | args = string.splitfields(text, ',') |
| 586 | n = len(args) |
| 587 | for i in range(n): |
| 588 | args[i] = string.strip(args[i]) |
| 589 | while len(args) < 3: args.append('') |
| 590 | node = args[0] |
| 591 | file = args[2] |
| 592 | self.write('`', file, '\', node `', node, '\'') |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 593 | |
| 594 | def makeref(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 595 | text = self.collectsavings() |
| 596 | args = string.splitfields(text, ',') |
| 597 | n = len(args) |
| 598 | for i in range(n): |
| 599 | args[i] = string.strip(args[i]) |
| 600 | while len(args) < 5: args.append('') |
| 601 | nodename = label = args[0] |
| 602 | if args[2]: label = args[2] |
| 603 | file = args[3] |
| 604 | title = args[4] |
| 605 | href = makefile(nodename) |
| 606 | if file: |
| 607 | href = '../' + file + '/' + href |
| 608 | self.write('<A HREF="', href, '">', label, '</A>') |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 609 | |
| 610 | # --- Marking Words and Phrases --- |
| 611 | |
| 612 | # --- Other @xxx{...} commands --- |
| 613 | |
| 614 | def open_(self): pass # Used by {text enclosed in braces} |
| 615 | def close_(self): pass |
| 616 | |
| 617 | open_asis = open_ |
| 618 | close_asis = close_ |
| 619 | |
| 620 | def open_cite(self): self.write('<CITE>') |
| 621 | def close_cite(self): self.write('</CITE>') |
| 622 | |
| 623 | def open_code(self): self.write('<CODE>') |
| 624 | def close_code(self): self.write('</CODE>') |
| 625 | |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 626 | def open_t(self): self.write('<TT>') |
| 627 | def close_t(self): self.write('</TT>') |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 628 | |
| 629 | def open_dfn(self): self.write('<DFN>') |
| 630 | def close_dfn(self): self.write('</DFN>') |
| 631 | |
| 632 | def open_emph(self): self.write('<EM>') |
| 633 | def close_emph(self): self.write('</EM>') |
| 634 | |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 635 | def open_i(self): self.write('<I>') |
| 636 | def close_i(self): self.write('</I>') |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 637 | |
| 638 | def open_footnote(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 639 | # if self.savetext <> None: |
| 640 | # print '*** Recursive footnote -- expect weirdness' |
| 641 | id = len(self.footnotes) + 1 |
| 642 | self.write(self.FN_SOURCE_PATTERN % {'id': `id`}) |
| 643 | self.startsaving() |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 644 | |
| 645 | def close_footnote(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 646 | id = len(self.footnotes) + 1 |
Guido van Rossum | 9c2c1e8 | 1998-10-08 15:24:48 +0000 | [diff] [blame] | 647 | self.footnotes.append((id, self.collectsavings())) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 648 | |
| 649 | def writefootnotes(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 650 | self.write(self.FN_HEADER) |
| 651 | for id, text in self.footnotes: |
| 652 | self.write(self.FN_TARGET_PATTERN |
| 653 | % {'id': `id`, 'text': text}) |
| 654 | self.footnotes = [] |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 655 | |
| 656 | def open_file(self): self.write('<CODE>') |
| 657 | def close_file(self): self.write('</CODE>') |
| 658 | |
| 659 | def open_kbd(self): self.write('<KBD>') |
| 660 | def close_kbd(self): self.write('</KBD>') |
| 661 | |
| 662 | def open_key(self): self.write('<KEY>') |
| 663 | def close_key(self): self.write('</KEY>') |
| 664 | |
| 665 | def open_r(self): self.write('<R>') |
| 666 | def close_r(self): self.write('</R>') |
| 667 | |
| 668 | def open_samp(self): self.write('`<SAMP>') |
| 669 | def close_samp(self): self.write('</SAMP>\'') |
| 670 | |
| 671 | def open_sc(self): self.write('<SMALLCAPS>') |
| 672 | def close_sc(self): self.write('</SMALLCAPS>') |
| 673 | |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 674 | def open_strong(self): self.write('<STRONG>') |
| 675 | def close_strong(self): self.write('</STRONG>') |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 676 | |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 677 | def open_b(self): self.write('<B>') |
| 678 | def close_b(self): self.write('</B>') |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 679 | |
| 680 | def open_var(self): self.write('<VAR>') |
| 681 | def close_var(self): self.write('</VAR>') |
| 682 | |
| 683 | def open_w(self): self.write('<NOBREAK>') |
| 684 | def close_w(self): self.write('</NOBREAK>') |
| 685 | |
Barry Warsaw | 6a508ae | 1998-04-23 22:59:33 +0000 | [diff] [blame] | 686 | def open_url(self): self.startsaving() |
| 687 | def close_url(self): |
| 688 | text = self.collectsavings() |
| 689 | self.write('<A HREF="', text, '">', text, '</A>') |
| 690 | |
| 691 | def open_email(self): self.startsaving() |
| 692 | def close_email(self): |
| 693 | text = self.collectsavings() |
| 694 | self.write('<A HREF="mailto:', text, '">', text, '</A>') |
| 695 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 696 | open_titlefont = open_ |
| 697 | close_titlefont = close_ |
| 698 | |
| 699 | def open_small(self): pass |
| 700 | def close_small(self): pass |
| 701 | |
Barry Warsaw | 6a508ae | 1998-04-23 22:59:33 +0000 | [diff] [blame] | 702 | def command(self, line, mo): |
| 703 | a, b = mo.span(1) |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 704 | cmd = line[a:b] |
| 705 | args = string.strip(line[b:]) |
| 706 | if self.debugging > 1: |
| 707 | print self.skip, self.stack, '@' + cmd, args |
| 708 | try: |
| 709 | func = getattr(self, 'do_' + cmd) |
| 710 | except AttributeError: |
| 711 | try: |
| 712 | func = getattr(self, 'bgn_' + cmd) |
| 713 | except AttributeError: |
| 714 | # don't complain if we are skipping anyway |
| 715 | if not self.skip: |
| 716 | self.unknown_cmd(cmd, args) |
| 717 | return |
| 718 | self.stack.append(cmd) |
| 719 | func(args) |
| 720 | return |
| 721 | if not self.skip or cmd == 'end': |
| 722 | func(args) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 723 | |
| 724 | def unknown_cmd(self, cmd, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 725 | print '*** unknown', '@' + cmd, args |
| 726 | if not self.unknown.has_key(cmd): |
| 727 | self.unknown[cmd] = 1 |
| 728 | else: |
| 729 | self.unknown[cmd] = self.unknown[cmd] + 1 |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 730 | |
| 731 | def do_end(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 732 | words = string.split(args) |
| 733 | if not words: |
| 734 | print '*** @end w/o args' |
| 735 | else: |
| 736 | cmd = words[0] |
| 737 | if not self.stack or self.stack[-1] <> cmd: |
| 738 | print '*** @end', cmd, 'unexpected' |
| 739 | else: |
| 740 | del self.stack[-1] |
| 741 | try: |
| 742 | func = getattr(self, 'end_' + cmd) |
| 743 | except AttributeError: |
| 744 | self.unknown_end(cmd) |
| 745 | return |
| 746 | func() |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 747 | |
| 748 | def unknown_end(self, cmd): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 749 | cmd = 'end ' + cmd |
| 750 | print '*** unknown', '@' + cmd |
| 751 | if not self.unknown.has_key(cmd): |
| 752 | self.unknown[cmd] = 1 |
| 753 | else: |
| 754 | self.unknown[cmd] = self.unknown[cmd] + 1 |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 755 | |
| 756 | # --- Comments --- |
| 757 | |
| 758 | def do_comment(self, args): pass |
| 759 | do_c = do_comment |
| 760 | |
| 761 | # --- Conditional processing --- |
| 762 | |
| 763 | def bgn_ifinfo(self, args): pass |
| 764 | def end_ifinfo(self): pass |
| 765 | |
| 766 | def bgn_iftex(self, args): self.skip = self.skip + 1 |
| 767 | def end_iftex(self): self.skip = self.skip - 1 |
| 768 | |
| 769 | def bgn_ignore(self, args): self.skip = self.skip + 1 |
| 770 | def end_ignore(self): self.skip = self.skip - 1 |
| 771 | |
| 772 | def bgn_tex(self, args): self.skip = self.skip + 1 |
| 773 | def end_tex(self): self.skip = self.skip - 1 |
| 774 | |
| 775 | def do_set(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 776 | fields = string.splitfields(args, ' ') |
| 777 | key = fields[0] |
| 778 | if len(fields) == 1: |
| 779 | value = 1 |
| 780 | else: |
| 781 | value = string.joinfields(fields[1:], ' ') |
| 782 | self.values[key] = value |
| 783 | print self.values |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 784 | |
| 785 | def do_clear(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 786 | self.values[args] = None |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 787 | |
| 788 | def bgn_ifset(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 789 | if args not in self.values.keys() \ |
| 790 | or self.values[args] is None: |
| 791 | self.skip = self.skip + 1 |
| 792 | self.stackinfo[len(self.stack)] = 1 |
| 793 | else: |
| 794 | self.stackinfo[len(self.stack)] = 0 |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 795 | def end_ifset(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 796 | print self.stack |
| 797 | print self.stackinfo |
| 798 | if self.stackinfo[len(self.stack) + 1]: |
| 799 | self.skip = self.skip - 1 |
| 800 | del self.stackinfo[len(self.stack) + 1] |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 801 | |
| 802 | def bgn_ifclear(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 803 | if args in self.values.keys() \ |
| 804 | and self.values[args] is not None: |
| 805 | self.skip = self.skip + 1 |
| 806 | self.stackinfo[len(self.stack)] = 1 |
| 807 | else: |
| 808 | self.stackinfo[len(self.stack)] = 0 |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 809 | |
| 810 | end_ifclear = end_ifset |
| 811 | |
| 812 | def open_value(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 813 | self.startsaving() |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 814 | |
| 815 | def close_value(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 816 | key = self.collectsavings() |
| 817 | if key in self.values.keys(): |
| 818 | self.write(self.values[key]) |
| 819 | else: |
| 820 | print '*** Undefined value: ', key |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 821 | |
| 822 | # --- Beginning a file --- |
| 823 | |
| 824 | do_finalout = do_comment |
| 825 | do_setchapternewpage = do_comment |
| 826 | do_setfilename = do_comment |
| 827 | |
| 828 | def do_settitle(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 829 | print args |
| 830 | self.startsaving() |
| 831 | self.expand(args) |
| 832 | self.title = self.collectsavings() |
| 833 | print self.title |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 834 | def do_parskip(self, args): pass |
| 835 | |
| 836 | # --- Ending a file --- |
| 837 | |
| 838 | def do_bye(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 839 | self.endnode() |
| 840 | self.done = 1 |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 841 | |
| 842 | # --- Title page --- |
| 843 | |
| 844 | def bgn_titlepage(self, args): self.skip = self.skip + 1 |
| 845 | def end_titlepage(self): self.skip = self.skip - 1 |
| 846 | def do_shorttitlepage(self, args): pass |
| 847 | |
| 848 | def do_center(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 849 | # Actually not used outside title page... |
| 850 | self.write('<H1>') |
| 851 | self.expand(args) |
| 852 | self.write('</H1>\n') |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 853 | do_title = do_center |
| 854 | do_subtitle = do_center |
| 855 | do_author = do_center |
| 856 | |
| 857 | do_vskip = do_comment |
| 858 | do_vfill = do_comment |
| 859 | do_smallbook = do_comment |
| 860 | |
| 861 | do_paragraphindent = do_comment |
| 862 | do_setchapternewpage = do_comment |
| 863 | do_headings = do_comment |
| 864 | do_footnotestyle = do_comment |
| 865 | |
| 866 | do_evenheading = do_comment |
| 867 | do_evenfooting = do_comment |
| 868 | do_oddheading = do_comment |
| 869 | do_oddfooting = do_comment |
| 870 | do_everyheading = do_comment |
| 871 | do_everyfooting = do_comment |
| 872 | |
| 873 | # --- Nodes --- |
| 874 | |
| 875 | def do_node(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 876 | self.endnode() |
| 877 | self.nodelineno = 0 |
| 878 | parts = string.splitfields(args, ',') |
| 879 | while len(parts) < 4: parts.append('') |
| 880 | for i in range(4): parts[i] = string.strip(parts[i]) |
| 881 | self.nodelinks = parts |
| 882 | [name, next, prev, up] = parts[:4] |
| 883 | file = self.dirname + '/' + makefile(name) |
| 884 | if self.filenames.has_key(file): |
| 885 | print '*** Filename already in use: ', file |
| 886 | else: |
| 887 | if self.debugging: print '--- writing', file |
| 888 | self.filenames[file] = 1 |
| 889 | # self.nodefp = open(file, 'w') |
| 890 | self.nodename = name |
| 891 | if self.cont and self.nodestack: |
| 892 | self.nodestack[-1].cont = self.nodename |
| 893 | if not self.topname: self.topname = name |
| 894 | title = name |
| 895 | if self.title: title = title + ' -- ' + self.title |
| 896 | self.node = self.Node(self.dirname, self.nodename, self.topname, |
| 897 | title, next, prev, up) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 898 | |
| 899 | def link(self, label, nodename): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 900 | if nodename: |
| 901 | if string.lower(nodename) == '(dir)': |
| 902 | addr = '../dir.html' |
| 903 | else: |
| 904 | addr = makefile(nodename) |
| 905 | self.write(label, ': <A HREF="', addr, '" TYPE="', |
| 906 | label, '">', nodename, '</A> \n') |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 907 | |
| 908 | # --- Sectioning commands --- |
| 909 | |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 910 | def popstack(self, type): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 911 | if (self.node): |
| 912 | self.node.type = type |
| 913 | while self.nodestack: |
| 914 | if self.nodestack[-1].type > type: |
| 915 | self.nodestack[-1].finalize() |
| 916 | self.nodestack[-1].flush() |
| 917 | del self.nodestack[-1] |
| 918 | elif self.nodestack[-1].type == type: |
| 919 | if not self.nodestack[-1].next: |
| 920 | self.nodestack[-1].next = self.node.name |
| 921 | if not self.node.prev: |
| 922 | self.node.prev = self.nodestack[-1].name |
| 923 | self.nodestack[-1].finalize() |
| 924 | self.nodestack[-1].flush() |
| 925 | del self.nodestack[-1] |
| 926 | else: |
| 927 | if type > 1 and not self.node.up: |
| 928 | self.node.up = self.nodestack[-1].name |
| 929 | break |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 930 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 931 | def do_chapter(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 932 | self.heading('H1', args, 0) |
| 933 | self.popstack(1) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 934 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 935 | def do_unnumbered(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 936 | self.heading('H1', args, -1) |
| 937 | self.popstack(1) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 938 | def do_appendix(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 939 | self.heading('H1', args, -1) |
| 940 | self.popstack(1) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 941 | def do_top(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 942 | self.heading('H1', args, -1) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 943 | def do_chapheading(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 944 | self.heading('H1', args, -1) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 945 | def do_majorheading(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 946 | self.heading('H1', args, -1) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 947 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 948 | def do_section(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 949 | self.heading('H1', args, 1) |
| 950 | self.popstack(2) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 951 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 952 | def do_unnumberedsec(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 953 | self.heading('H1', args, -1) |
| 954 | self.popstack(2) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 955 | def do_appendixsec(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 956 | self.heading('H1', args, -1) |
| 957 | self.popstack(2) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 958 | do_appendixsection = do_appendixsec |
| 959 | def do_heading(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 960 | self.heading('H1', args, -1) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 961 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 962 | def do_subsection(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 963 | self.heading('H2', args, 2) |
| 964 | self.popstack(3) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 965 | def do_unnumberedsubsec(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 966 | self.heading('H2', args, -1) |
| 967 | self.popstack(3) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 968 | def do_appendixsubsec(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 969 | self.heading('H2', args, -1) |
| 970 | self.popstack(3) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 971 | def do_subheading(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 972 | self.heading('H2', args, -1) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 973 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 974 | def do_subsubsection(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 975 | self.heading('H3', args, 3) |
| 976 | self.popstack(4) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 977 | def do_unnumberedsubsubsec(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 978 | self.heading('H3', args, -1) |
| 979 | self.popstack(4) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 980 | def do_appendixsubsubsec(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 981 | self.heading('H3', args, -1) |
| 982 | self.popstack(4) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 983 | def do_subsubheading(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 984 | self.heading('H3', args, -1) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 985 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 986 | def heading(self, type, args, level): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 987 | if level >= 0: |
| 988 | while len(self.numbering) <= level: |
| 989 | self.numbering.append(0) |
| 990 | del self.numbering[level+1:] |
| 991 | self.numbering[level] = self.numbering[level] + 1 |
| 992 | x = '' |
| 993 | for i in self.numbering: |
| 994 | x = x + `i` + '.' |
| 995 | args = x + ' ' + args |
Guido van Rossum | 9c2c1e8 | 1998-10-08 15:24:48 +0000 | [diff] [blame] | 996 | self.contents.append((level, args, self.nodename)) |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 997 | self.write('<', type, '>') |
| 998 | self.expand(args) |
| 999 | self.write('</', type, '>\n') |
| 1000 | if self.debugging or self.print_headers: |
| 1001 | print '---', args |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1002 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1003 | def do_contents(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1004 | # pass |
| 1005 | self.listcontents('Table of Contents', 999) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1006 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1007 | def do_shortcontents(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1008 | pass |
| 1009 | # self.listcontents('Short Contents', 0) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1010 | do_summarycontents = do_shortcontents |
Guido van Rossum | a12bbff | 1995-05-03 14:17:36 +0000 | [diff] [blame] | 1011 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1012 | def listcontents(self, title, maxlevel): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1013 | self.write('<H1>', title, '</H1>\n<UL COMPACT PLAIN>\n') |
| 1014 | prevlevels = [0] |
| 1015 | for level, title, node in self.contents: |
| 1016 | if level > maxlevel: |
| 1017 | continue |
| 1018 | if level > prevlevels[-1]: |
| 1019 | # can only advance one level at a time |
| 1020 | self.write(' '*prevlevels[-1], '<UL PLAIN>\n') |
| 1021 | prevlevels.append(level) |
| 1022 | elif level < prevlevels[-1]: |
| 1023 | # might drop back multiple levels |
| 1024 | while level < prevlevels[-1]: |
| 1025 | del prevlevels[-1] |
| 1026 | self.write(' '*prevlevels[-1], |
| 1027 | '</UL>\n') |
| 1028 | self.write(' '*level, '<LI> <A HREF="', |
| 1029 | makefile(node), '">') |
| 1030 | self.expand(title) |
| 1031 | self.write('</A>\n') |
| 1032 | self.write('</UL>\n' * len(prevlevels)) |
Guido van Rossum | 06f4289 | 1995-08-28 03:01:00 +0000 | [diff] [blame] | 1033 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1034 | # --- Page lay-out --- |
Guido van Rossum | 06f4289 | 1995-08-28 03:01:00 +0000 | [diff] [blame] | 1035 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1036 | # These commands are only meaningful in printed text |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1037 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1038 | def do_page(self, args): pass |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1039 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1040 | def do_need(self, args): pass |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1041 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1042 | def bgn_group(self, args): pass |
| 1043 | def end_group(self): pass |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1044 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1045 | # --- Line lay-out --- |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1046 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1047 | def do_sp(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1048 | if self.nofill: |
| 1049 | self.write('\n') |
| 1050 | else: |
| 1051 | self.write('<P>\n') |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1052 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1053 | def do_hline(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1054 | self.write('<HR>') |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1055 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1056 | # --- Function and variable definitions --- |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1057 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1058 | def bgn_deffn(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1059 | self.write('<DL>') |
| 1060 | self.do_deffnx(args) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1061 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1062 | def end_deffn(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1063 | self.write('</DL>\n') |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1064 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1065 | def do_deffnx(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1066 | self.write('<DT>') |
| 1067 | words = splitwords(args, 2) |
| 1068 | [category, name], rest = words[:2], words[2:] |
| 1069 | self.expand('@b{%s}' % name) |
| 1070 | for word in rest: self.expand(' ' + makevar(word)) |
| 1071 | #self.expand(' -- ' + category) |
| 1072 | self.write('\n<DD>') |
| 1073 | self.index('fn', name) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1074 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1075 | def bgn_defun(self, args): self.bgn_deffn('Function ' + args) |
| 1076 | end_defun = end_deffn |
| 1077 | def do_defunx(self, args): self.do_deffnx('Function ' + args) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1078 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1079 | def bgn_defmac(self, args): self.bgn_deffn('Macro ' + args) |
| 1080 | end_defmac = end_deffn |
| 1081 | def do_defmacx(self, args): self.do_deffnx('Macro ' + args) |
Guido van Rossum | 06f4289 | 1995-08-28 03:01:00 +0000 | [diff] [blame] | 1082 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1083 | def bgn_defspec(self, args): self.bgn_deffn('{Special Form} ' + args) |
| 1084 | end_defspec = end_deffn |
| 1085 | def do_defspecx(self, args): self.do_deffnx('{Special Form} ' + args) |
Guido van Rossum | 06f4289 | 1995-08-28 03:01:00 +0000 | [diff] [blame] | 1086 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1087 | def bgn_defvr(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1088 | self.write('<DL>') |
| 1089 | self.do_defvrx(args) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1090 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1091 | end_defvr = end_deffn |
Guido van Rossum | 06f4289 | 1995-08-28 03:01:00 +0000 | [diff] [blame] | 1092 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1093 | def do_defvrx(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1094 | self.write('<DT>') |
| 1095 | words = splitwords(args, 2) |
| 1096 | [category, name], rest = words[:2], words[2:] |
| 1097 | self.expand('@code{%s}' % name) |
| 1098 | # If there are too many arguments, show them |
| 1099 | for word in rest: self.expand(' ' + word) |
| 1100 | #self.expand(' -- ' + category) |
| 1101 | self.write('\n<DD>') |
| 1102 | self.index('vr', name) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1103 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1104 | def bgn_defvar(self, args): self.bgn_defvr('Variable ' + args) |
| 1105 | end_defvar = end_defvr |
| 1106 | def do_defvarx(self, args): self.do_defvrx('Variable ' + args) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1107 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1108 | def bgn_defopt(self, args): self.bgn_defvr('{User Option} ' + args) |
| 1109 | end_defopt = end_defvr |
| 1110 | def do_defoptx(self, args): self.do_defvrx('{User Option} ' + args) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1111 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1112 | # --- Ditto for typed languages --- |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1113 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1114 | def bgn_deftypefn(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1115 | self.write('<DL>') |
| 1116 | self.do_deftypefnx(args) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1117 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1118 | end_deftypefn = end_deffn |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1119 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1120 | def do_deftypefnx(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1121 | self.write('<DT>') |
| 1122 | words = splitwords(args, 3) |
| 1123 | [category, datatype, name], rest = words[:3], words[3:] |
| 1124 | self.expand('@code{%s} @b{%s}' % (datatype, name)) |
| 1125 | for word in rest: self.expand(' ' + makevar(word)) |
| 1126 | #self.expand(' -- ' + category) |
| 1127 | self.write('\n<DD>') |
| 1128 | self.index('fn', name) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1129 | |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1130 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1131 | def bgn_deftypefun(self, args): self.bgn_deftypefn('Function ' + args) |
| 1132 | end_deftypefun = end_deftypefn |
| 1133 | def do_deftypefunx(self, args): self.do_deftypefnx('Function ' + args) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1134 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1135 | def bgn_deftypevr(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1136 | self.write('<DL>') |
| 1137 | self.do_deftypevrx(args) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1138 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1139 | end_deftypevr = end_deftypefn |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1140 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1141 | def do_deftypevrx(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1142 | self.write('<DT>') |
| 1143 | words = splitwords(args, 3) |
| 1144 | [category, datatype, name], rest = words[:3], words[3:] |
| 1145 | self.expand('@code{%s} @b{%s}' % (datatype, name)) |
| 1146 | # If there are too many arguments, show them |
| 1147 | for word in rest: self.expand(' ' + word) |
| 1148 | #self.expand(' -- ' + category) |
| 1149 | self.write('\n<DD>') |
| 1150 | self.index('fn', name) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1151 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1152 | def bgn_deftypevar(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1153 | self.bgn_deftypevr('Variable ' + args) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1154 | end_deftypevar = end_deftypevr |
| 1155 | def do_deftypevarx(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1156 | self.do_deftypevrx('Variable ' + args) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1157 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1158 | # --- Ditto for object-oriented languages --- |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1159 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1160 | def bgn_defcv(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1161 | self.write('<DL>') |
| 1162 | self.do_defcvx(args) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1163 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1164 | end_defcv = end_deftypevr |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1165 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1166 | def do_defcvx(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1167 | self.write('<DT>') |
| 1168 | words = splitwords(args, 3) |
| 1169 | [category, classname, name], rest = words[:3], words[3:] |
| 1170 | self.expand('@b{%s}' % name) |
| 1171 | # If there are too many arguments, show them |
| 1172 | for word in rest: self.expand(' ' + word) |
| 1173 | #self.expand(' -- %s of @code{%s}' % (category, classname)) |
| 1174 | self.write('\n<DD>') |
| 1175 | self.index('vr', '%s @r{on %s}' % (name, classname)) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1176 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1177 | def bgn_defivar(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1178 | self.bgn_defcv('{Instance Variable} ' + args) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1179 | end_defivar = end_defcv |
| 1180 | def do_defivarx(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1181 | self.do_defcvx('{Instance Variable} ' + args) |
Guido van Rossum | a12bbff | 1995-05-03 14:17:36 +0000 | [diff] [blame] | 1182 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1183 | def bgn_defop(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1184 | self.write('<DL>') |
| 1185 | self.do_defopx(args) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1186 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1187 | end_defop = end_defcv |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1188 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1189 | def do_defopx(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1190 | self.write('<DT>') |
| 1191 | words = splitwords(args, 3) |
| 1192 | [category, classname, name], rest = words[:3], words[3:] |
| 1193 | self.expand('@b{%s}' % name) |
| 1194 | for word in rest: self.expand(' ' + makevar(word)) |
| 1195 | #self.expand(' -- %s of @code{%s}' % (category, classname)) |
| 1196 | self.write('\n<DD>') |
| 1197 | self.index('fn', '%s @r{on %s}' % (name, classname)) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1198 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1199 | def bgn_defmethod(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1200 | self.bgn_defop('Method ' + args) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1201 | end_defmethod = end_defop |
| 1202 | def do_defmethodx(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1203 | self.do_defopx('Method ' + args) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1204 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1205 | # --- Ditto for data types --- |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1206 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1207 | def bgn_deftp(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1208 | self.write('<DL>') |
| 1209 | self.do_deftpx(args) |
Guido van Rossum | 06f4289 | 1995-08-28 03:01:00 +0000 | [diff] [blame] | 1210 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1211 | end_deftp = end_defcv |
Guido van Rossum | 06f4289 | 1995-08-28 03:01:00 +0000 | [diff] [blame] | 1212 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1213 | def do_deftpx(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1214 | self.write('<DT>') |
| 1215 | words = splitwords(args, 2) |
| 1216 | [category, name], rest = words[:2], words[2:] |
| 1217 | self.expand('@b{%s}' % name) |
| 1218 | for word in rest: self.expand(' ' + word) |
| 1219 | #self.expand(' -- ' + category) |
| 1220 | self.write('\n<DD>') |
| 1221 | self.index('tp', name) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1222 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1223 | # --- Making Lists and Tables |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1224 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1225 | def bgn_enumerate(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1226 | if not args: |
| 1227 | self.write('<OL>\n') |
| 1228 | self.stackinfo[len(self.stack)] = '</OL>\n' |
| 1229 | else: |
| 1230 | self.itemnumber = args |
| 1231 | self.write('<UL>\n') |
| 1232 | self.stackinfo[len(self.stack)] = '</UL>\n' |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1233 | def end_enumerate(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1234 | self.itemnumber = None |
| 1235 | self.write(self.stackinfo[len(self.stack) + 1]) |
| 1236 | del self.stackinfo[len(self.stack) + 1] |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1237 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1238 | def bgn_itemize(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1239 | self.itemarg = args |
| 1240 | self.write('<UL>\n') |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1241 | def end_itemize(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1242 | self.itemarg = None |
| 1243 | self.write('</UL>\n') |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1244 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1245 | def bgn_table(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1246 | self.itemarg = args |
| 1247 | self.write('<DL>\n') |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1248 | def end_table(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1249 | self.itemarg = None |
| 1250 | self.write('</DL>\n') |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1251 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1252 | def bgn_ftable(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1253 | self.itemindex = 'fn' |
| 1254 | self.bgn_table(args) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1255 | def end_ftable(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1256 | self.itemindex = None |
| 1257 | self.end_table() |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1258 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1259 | def do_item(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1260 | if self.itemindex: self.index(self.itemindex, args) |
| 1261 | if self.itemarg: |
| 1262 | if self.itemarg[0] == '@' and self.itemarg[1:2] and \ |
Fred Drake | 79e75e1 | 2001-07-20 19:05:50 +0000 | [diff] [blame] | 1263 | self.itemarg[1] in string.ascii_letters: |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1264 | args = self.itemarg + '{' + args + '}' |
| 1265 | else: |
| 1266 | # some other character, e.g. '-' |
| 1267 | args = self.itemarg + ' ' + args |
| 1268 | if self.itemnumber <> None: |
| 1269 | args = self.itemnumber + '. ' + args |
| 1270 | self.itemnumber = increment(self.itemnumber) |
| 1271 | if self.stack and self.stack[-1] == 'table': |
| 1272 | self.write('<DT>') |
| 1273 | self.expand(args) |
| 1274 | self.write('\n<DD>') |
| 1275 | else: |
| 1276 | self.write('<LI>') |
| 1277 | self.expand(args) |
| 1278 | self.write(' ') |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1279 | do_itemx = do_item # XXX Should suppress leading blank line |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1280 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1281 | # --- Enumerations, displays, quotations --- |
| 1282 | # XXX Most of these should increase the indentation somehow |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1283 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1284 | def bgn_quotation(self, args): self.write('<BLOCKQUOTE>') |
| 1285 | def end_quotation(self): self.write('</BLOCKQUOTE>\n') |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1286 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1287 | def bgn_example(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1288 | self.nofill = self.nofill + 1 |
| 1289 | self.write('<PRE>') |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1290 | def end_example(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1291 | self.write('</PRE>\n') |
| 1292 | self.nofill = self.nofill - 1 |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1293 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1294 | bgn_lisp = bgn_example # Synonym when contents are executable lisp code |
| 1295 | end_lisp = end_example |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1296 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1297 | bgn_smallexample = bgn_example # XXX Should use smaller font |
| 1298 | end_smallexample = end_example |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1299 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1300 | bgn_smalllisp = bgn_lisp # Ditto |
| 1301 | end_smalllisp = end_lisp |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1302 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1303 | bgn_display = bgn_example |
| 1304 | end_display = end_example |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1305 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1306 | bgn_format = bgn_display |
| 1307 | end_format = end_display |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1308 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1309 | def do_exdent(self, args): self.expand(args + '\n') |
| 1310 | # XXX Should really mess with indentation |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1311 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1312 | def bgn_flushleft(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1313 | self.nofill = self.nofill + 1 |
| 1314 | self.write('<PRE>\n') |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1315 | def end_flushleft(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1316 | self.write('</PRE>\n') |
| 1317 | self.nofill = self.nofill - 1 |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1318 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1319 | def bgn_flushright(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1320 | self.nofill = self.nofill + 1 |
| 1321 | self.write('<ADDRESS COMPACT>\n') |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1322 | def end_flushright(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1323 | self.write('</ADDRESS>\n') |
| 1324 | self.nofill = self.nofill - 1 |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1325 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1326 | def bgn_menu(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1327 | self.write('<DIR>\n') |
| 1328 | self.write(' <STRONG><EM>Menu</EM></STRONG><P>\n') |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 1329 | def end_menu(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1330 | self.write('</DIR>\n') |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1331 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1332 | def bgn_cartouche(self, args): pass |
| 1333 | def end_cartouche(self): pass |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1334 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1335 | # --- Indices --- |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1336 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1337 | def resetindex(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1338 | self.noncodeindices = ['cp'] |
| 1339 | self.indextitle = {} |
| 1340 | self.indextitle['cp'] = 'Concept' |
| 1341 | self.indextitle['fn'] = 'Function' |
| 1342 | self.indextitle['ky'] = 'Keyword' |
| 1343 | self.indextitle['pg'] = 'Program' |
| 1344 | self.indextitle['tp'] = 'Type' |
| 1345 | self.indextitle['vr'] = 'Variable' |
| 1346 | # |
| 1347 | self.whichindex = {} |
| 1348 | for name in self.indextitle.keys(): |
| 1349 | self.whichindex[name] = [] |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1350 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1351 | def user_index(self, name, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1352 | if self.whichindex.has_key(name): |
| 1353 | self.index(name, args) |
| 1354 | else: |
| 1355 | print '*** No index named', `name` |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1356 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1357 | def do_cindex(self, args): self.index('cp', args) |
| 1358 | def do_findex(self, args): self.index('fn', args) |
| 1359 | def do_kindex(self, args): self.index('ky', args) |
| 1360 | def do_pindex(self, args): self.index('pg', args) |
| 1361 | def do_tindex(self, args): self.index('tp', args) |
| 1362 | def do_vindex(self, args): self.index('vr', args) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1363 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1364 | def index(self, name, args): |
Guido van Rossum | 9c2c1e8 | 1998-10-08 15:24:48 +0000 | [diff] [blame] | 1365 | self.whichindex[name].append((args, self.nodename)) |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1366 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1367 | def do_synindex(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1368 | words = string.split(args) |
| 1369 | if len(words) <> 2: |
| 1370 | print '*** bad @synindex', args |
| 1371 | return |
| 1372 | [old, new] = words |
| 1373 | if not self.whichindex.has_key(old) or \ |
| 1374 | not self.whichindex.has_key(new): |
| 1375 | print '*** bad key(s) in @synindex', args |
| 1376 | return |
| 1377 | if old <> new and \ |
| 1378 | self.whichindex[old] is not self.whichindex[new]: |
| 1379 | inew = self.whichindex[new] |
| 1380 | inew[len(inew):] = self.whichindex[old] |
| 1381 | self.whichindex[old] = inew |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1382 | do_syncodeindex = do_synindex # XXX Should use code font |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1383 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1384 | def do_printindex(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1385 | words = string.split(args) |
| 1386 | for name in words: |
| 1387 | if self.whichindex.has_key(name): |
| 1388 | self.prindex(name) |
| 1389 | else: |
| 1390 | print '*** No index named', `name` |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1391 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1392 | def prindex(self, name): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1393 | iscodeindex = (name not in self.noncodeindices) |
| 1394 | index = self.whichindex[name] |
| 1395 | if not index: return |
| 1396 | if self.debugging: |
| 1397 | print '--- Generating', self.indextitle[name], 'index' |
| 1398 | # The node already provides a title |
| 1399 | index1 = [] |
Barry Warsaw | 6a508ae | 1998-04-23 22:59:33 +0000 | [diff] [blame] | 1400 | junkprog = re.compile('^(@[a-z]+)?{') |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1401 | for key, node in index: |
| 1402 | sortkey = string.lower(key) |
| 1403 | # Remove leading `@cmd{' from sort key |
| 1404 | # -- don't bother about the matching `}' |
| 1405 | oldsortkey = sortkey |
| 1406 | while 1: |
Barry Warsaw | 6a508ae | 1998-04-23 22:59:33 +0000 | [diff] [blame] | 1407 | mo = junkprog.match(sortkey) |
| 1408 | if not mo: |
| 1409 | break |
| 1410 | i = mo.end() |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1411 | sortkey = sortkey[i:] |
Guido van Rossum | 9c2c1e8 | 1998-10-08 15:24:48 +0000 | [diff] [blame] | 1412 | index1.append((sortkey, key, node)) |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1413 | del index[:] |
| 1414 | index1.sort() |
| 1415 | self.write('<DL COMPACT>\n') |
| 1416 | prevkey = prevnode = None |
| 1417 | for sortkey, key, node in index1: |
| 1418 | if (key, node) == (prevkey, prevnode): |
| 1419 | continue |
| 1420 | if self.debugging > 1: print key, ':', node |
| 1421 | self.write('<DT>') |
| 1422 | if iscodeindex: key = '@code{' + key + '}' |
| 1423 | if key != prevkey: |
| 1424 | self.expand(key) |
| 1425 | self.write('\n<DD><A HREF="%s">%s</A>\n' % (makefile(node), node)) |
| 1426 | prevkey, prevnode = key, node |
| 1427 | self.write('</DL>\n') |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1428 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1429 | # --- Final error reports --- |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1430 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1431 | def report(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1432 | if self.unknown: |
| 1433 | print '--- Unrecognized commands ---' |
| 1434 | cmds = self.unknown.keys() |
| 1435 | cmds.sort() |
| 1436 | for cmd in cmds: |
| 1437 | print string.ljust(cmd, 20), self.unknown[cmd] |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1438 | |
| 1439 | |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 1440 | class TexinfoParserHTML3(TexinfoParser): |
| 1441 | |
| 1442 | COPYRIGHT_SYMBOL = "©" |
| 1443 | FN_ID_PATTERN = "[%(id)s]" |
| 1444 | FN_SOURCE_PATTERN = '<A ID=footnoteref%(id)s ' \ |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1445 | 'HREF="#footnotetext%(id)s">' + FN_ID_PATTERN + '</A>' |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 1446 | FN_TARGET_PATTERN = '<FN ID=footnotetext%(id)s>\n' \ |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1447 | '<P><A HREF="#footnoteref%(id)s">' + FN_ID_PATTERN \ |
| 1448 | + '</A>\n%(text)s</P></FN>\n' |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 1449 | FN_HEADER = '<DIV CLASS=footnotes>\n <HR NOSHADE WIDTH=200>\n' \ |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1450 | ' <STRONG><EM>Footnotes</EM></STRONG>\n <P>\n' |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 1451 | |
| 1452 | Node = HTML3Node |
| 1453 | |
| 1454 | def bgn_quotation(self, args): self.write('<BQ>') |
| 1455 | def end_quotation(self): self.write('</BQ>\n') |
| 1456 | |
| 1457 | def bgn_example(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1458 | # this use of <CODE> would not be legal in HTML 2.0, |
| 1459 | # but is in more recent DTDs. |
| 1460 | self.nofill = self.nofill + 1 |
| 1461 | self.write('<PRE CLASS=example><CODE>') |
Fred Drake | abcb382 | 1996-10-25 22:13:59 +0000 | [diff] [blame] | 1462 | def end_example(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1463 | self.write("</CODE></PRE>\n") |
| 1464 | self.nofill = self.nofill - 1 |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 1465 | |
| 1466 | def bgn_flushleft(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1467 | self.nofill = self.nofill + 1 |
| 1468 | self.write('<PRE CLASS=flushleft>\n') |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 1469 | |
| 1470 | def bgn_flushright(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1471 | self.nofill = self.nofill + 1 |
| 1472 | self.write('<DIV ALIGN=right CLASS=flushright><ADDRESS COMPACT>\n') |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 1473 | def end_flushright(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1474 | self.write('</ADDRESS></DIV>\n') |
| 1475 | self.nofill = self.nofill - 1 |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 1476 | |
| 1477 | def bgn_menu(self, args): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1478 | self.write('<UL PLAIN CLASS=menu>\n') |
| 1479 | self.write(' <LH>Menu</LH>\n') |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 1480 | def end_menu(self): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1481 | self.write('</UL>\n') |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 1482 | |
| 1483 | |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1484 | # Put @var{} around alphabetic substrings |
| 1485 | def makevar(str): |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1486 | return '@var{'+str+'}' |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1487 | |
| 1488 | |
| 1489 | # Split a string in "words" according to findwordend |
| 1490 | def splitwords(str, minlength): |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1491 | words = [] |
| 1492 | i = 0 |
| 1493 | n = len(str) |
| 1494 | while i < n: |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1495 | while i < n and str[i] in ' \t\n': i = i+1 |
| 1496 | if i >= n: break |
| 1497 | start = i |
| 1498 | i = findwordend(str, i, n) |
| 1499 | words.append(str[start:i]) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1500 | while len(words) < minlength: words.append('') |
| 1501 | return words |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1502 | |
| 1503 | |
| 1504 | # Find the end of a "word", matching braces and interpreting @@ @{ @} |
Barry Warsaw | 6a508ae | 1998-04-23 22:59:33 +0000 | [diff] [blame] | 1505 | fwprog = re.compile('[@{} ]') |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1506 | def findwordend(str, i, n): |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1507 | level = 0 |
| 1508 | while i < n: |
Barry Warsaw | 6a508ae | 1998-04-23 22:59:33 +0000 | [diff] [blame] | 1509 | mo = fwprog.search(str, i) |
| 1510 | if not mo: |
| 1511 | break |
| 1512 | i = mo.start() |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1513 | c = str[i]; i = i+1 |
| 1514 | if c == '@': i = i+1 # Next character is not special |
| 1515 | elif c == '{': level = level+1 |
| 1516 | elif c == '}': level = level-1 |
| 1517 | elif c == ' ' and level <= 0: return i-1 |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1518 | return n |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1519 | |
| 1520 | |
| 1521 | # Convert a node name into a file name |
| 1522 | def makefile(nodename): |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1523 | return fixfunnychars(nodename) + '.html' |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1524 | |
| 1525 | |
| 1526 | # Characters that are perfectly safe in filenames and hyperlinks |
Fred Drake | 79e75e1 | 2001-07-20 19:05:50 +0000 | [diff] [blame] | 1527 | goodchars = string.ascii_letters + string.digits + '!@-=+.' |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1528 | |
Guido van Rossum | 06f4289 | 1995-08-28 03:01:00 +0000 | [diff] [blame] | 1529 | # Replace characters that aren't perfectly safe by dashes |
| 1530 | # Underscores are bad since Cern HTTPD treats them as delimiters for |
| 1531 | # encoding times, so you get mismatches if you compress your files: |
| 1532 | # a.html.gz will map to a_b.html.gz |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1533 | def fixfunnychars(addr): |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1534 | i = 0 |
| 1535 | while i < len(addr): |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1536 | c = addr[i] |
| 1537 | if c not in goodchars: |
| 1538 | c = '-' |
| 1539 | addr = addr[:i] + c + addr[i+1:] |
| 1540 | i = i + len(c) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1541 | return addr |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1542 | |
| 1543 | |
| 1544 | # Increment a string used as an enumeration |
| 1545 | def increment(s): |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1546 | if not s: |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1547 | return '1' |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1548 | for sequence in string.digits, string.lowercase, string.uppercase: |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1549 | lastc = s[-1] |
| 1550 | if lastc in sequence: |
| 1551 | i = string.index(sequence, lastc) + 1 |
| 1552 | if i >= len(sequence): |
| 1553 | if len(s) == 1: |
| 1554 | s = sequence[0]*2 |
| 1555 | if s == '00': |
| 1556 | s = '10' |
| 1557 | else: |
| 1558 | s = increment(s[:-1]) + sequence[0] |
| 1559 | else: |
| 1560 | s = s[:-1] + sequence[i] |
| 1561 | return s |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1562 | return s # Don't increment |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1563 | |
| 1564 | |
| 1565 | def test(): |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1566 | import sys |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 1567 | debugging = 0 |
| 1568 | print_headers = 0 |
| 1569 | cont = 0 |
| 1570 | html3 = 0 |
Tim Peters | 70c4378 | 2001-01-17 08:48:39 +0000 | [diff] [blame] | 1571 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1572 | while sys.argv[1:2] == ['-d']: |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1573 | debugging = debugging + 1 |
| 1574 | del sys.argv[1:2] |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 1575 | if sys.argv[1] == '-p': |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1576 | print_headers = 1 |
| 1577 | del sys.argv[1] |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1578 | if sys.argv[1] == '-c': |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1579 | cont = 1 |
| 1580 | del sys.argv[1] |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 1581 | if sys.argv[1] == '-3': |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1582 | html3 = 1 |
| 1583 | del sys.argv[1] |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1584 | if len(sys.argv) <> 3: |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1585 | print 'usage: texi2html [-d [-d]] [-p] [-c] inputfile outputdirectory' |
| 1586 | sys.exit(2) |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 1587 | |
| 1588 | if html3: |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1589 | parser = TexinfoParserHTML3() |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 1590 | else: |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1591 | parser = TexinfoParser() |
Fred Drake | 0282726 | 1996-10-09 19:05:12 +0000 | [diff] [blame] | 1592 | parser.cont = cont |
| 1593 | parser.debugging = debugging |
| 1594 | parser.print_headers = print_headers |
| 1595 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1596 | file = sys.argv[1] |
| 1597 | parser.setdirname(sys.argv[2]) |
| 1598 | if file == '-': |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1599 | fp = sys.stdin |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1600 | else: |
Guido van Rossum | caf9fca | 1998-09-14 16:03:02 +0000 | [diff] [blame] | 1601 | parser.setincludedir(os.path.dirname(file)) |
| 1602 | try: |
| 1603 | fp = open(file, 'r') |
| 1604 | except IOError, msg: |
| 1605 | print file, ':', msg |
| 1606 | sys.exit(1) |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1607 | parser.parse(fp) |
| 1608 | fp.close() |
| 1609 | parser.report() |
Guido van Rossum | 26a9d37 | 1995-03-15 11:26:05 +0000 | [diff] [blame] | 1610 | |
| 1611 | |
Fred Drake | a39a25e | 1996-09-13 14:44:34 +0000 | [diff] [blame] | 1612 | if __name__ == "__main__": |
| 1613 | test() |