1 | n/a | #! /usr/bin/env python3 |
---|
2 | n/a | |
---|
3 | n/a | # Convert GNU texinfo files into HTML, one file per node. |
---|
4 | n/a | # Based on Texinfo 2.14. |
---|
5 | n/a | # Usage: texi2html [-d] [-d] [-c] inputfile outputdirectory |
---|
6 | n/a | # The input file must be a complete texinfo file, e.g. emacs.texi. |
---|
7 | n/a | # This creates many files (one per info node) in the output directory, |
---|
8 | n/a | # overwriting existing files of the same name. All files created have |
---|
9 | n/a | # ".html" as their extension. |
---|
10 | n/a | |
---|
11 | n/a | |
---|
12 | n/a | # XXX To do: |
---|
13 | n/a | # - handle @comment*** correctly |
---|
14 | n/a | # - handle @xref {some words} correctly |
---|
15 | n/a | # - handle @ftable correctly (items aren't indexed?) |
---|
16 | n/a | # - handle @itemx properly |
---|
17 | n/a | # - handle @exdent properly |
---|
18 | n/a | # - add links directly to the proper line from indices |
---|
19 | n/a | # - check against the definitive list of @-cmds; we still miss (among others): |
---|
20 | n/a | # - @defindex (hard) |
---|
21 | n/a | # - @c(omment) in the middle of a line (rarely used) |
---|
22 | n/a | # - @this* (not really needed, only used in headers anyway) |
---|
23 | n/a | # - @today{} (ever used outside title page?) |
---|
24 | n/a | |
---|
25 | n/a | # More consistent handling of chapters/sections/etc. |
---|
26 | n/a | # Lots of documentation |
---|
27 | n/a | # Many more options: |
---|
28 | n/a | # -top designate top node |
---|
29 | n/a | # -links customize which types of links are included |
---|
30 | n/a | # -split split at chapters or sections instead of nodes |
---|
31 | n/a | # -name Allow different types of filename handling. Non unix systems |
---|
32 | n/a | # will have problems with long node names |
---|
33 | n/a | # ... |
---|
34 | n/a | # Support the most recent texinfo version and take a good look at HTML 3.0 |
---|
35 | n/a | # More debugging output (customizable) and more flexible error handling |
---|
36 | n/a | # How about icons ? |
---|
37 | n/a | |
---|
38 | n/a | # rpyron 2002-05-07 |
---|
39 | n/a | # Robert Pyron <rpyron@alum.mit.edu> |
---|
40 | n/a | # 1. BUGFIX: In function makefile(), strip blanks from the nodename. |
---|
41 | n/a | # This is necessary to match the behavior of parser.makeref() and |
---|
42 | n/a | # parser.do_node(). |
---|
43 | n/a | # 2. BUGFIX fixed KeyError in end_ifset (well, I may have just made |
---|
44 | n/a | # it go away, rather than fix it) |
---|
45 | n/a | # 3. BUGFIX allow @menu and menu items inside @ifset or @ifclear |
---|
46 | n/a | # 4. Support added for: |
---|
47 | n/a | # @uref URL reference |
---|
48 | n/a | # @image image file reference (see note below) |
---|
49 | n/a | # @multitable output an HTML table |
---|
50 | n/a | # @vtable |
---|
51 | n/a | # 5. Partial support for accents, to match MAKEINFO output |
---|
52 | n/a | # 6. I added a new command-line option, '-H basename', to specify |
---|
53 | n/a | # HTML Help output. This will cause three files to be created |
---|
54 | n/a | # in the current directory: |
---|
55 | n/a | # `basename`.hhp HTML Help Workshop project file |
---|
56 | n/a | # `basename`.hhc Contents file for the project |
---|
57 | n/a | # `basename`.hhk Index file for the project |
---|
58 | n/a | # When fed into HTML Help Workshop, the resulting file will be |
---|
59 | n/a | # named `basename`.chm. |
---|
60 | n/a | # 7. A new class, HTMLHelp, to accomplish item 6. |
---|
61 | n/a | # 8. Various calls to HTMLHelp functions. |
---|
62 | n/a | # A NOTE ON IMAGES: Just as 'outputdirectory' must exist before |
---|
63 | n/a | # running this program, all referenced images must already exist |
---|
64 | n/a | # in outputdirectory. |
---|
65 | n/a | |
---|
66 | n/a | import os |
---|
67 | n/a | import sys |
---|
68 | n/a | import string |
---|
69 | n/a | import re |
---|
70 | n/a | |
---|
71 | n/a | MAGIC = '\\input texinfo' |
---|
72 | n/a | |
---|
73 | n/a | cmprog = re.compile('^@([a-z]+)([ \t]|$)') # Command (line-oriented) |
---|
74 | n/a | blprog = re.compile('^[ \t]*$') # Blank line |
---|
75 | n/a | kwprog = re.compile('@[a-z]+') # Keyword (embedded, usually |
---|
76 | n/a | # with {} args) |
---|
77 | n/a | spprog = re.compile('[\n@{}&<>]') # Special characters in |
---|
78 | n/a | # running text |
---|
79 | n/a | # |
---|
80 | n/a | # menu item (Yuck!) |
---|
81 | n/a | miprog = re.compile(r'^\* ([^:]*):(:|[ \t]*([^\t,\n.]+)([^ \t\n]*))[ \t\n]*') |
---|
82 | n/a | # 0 1 1 2 3 34 42 0 |
---|
83 | n/a | # ----- ---------- --------- |
---|
84 | n/a | # -|----------------------------- |
---|
85 | n/a | # ----------------------------------------------------- |
---|
86 | n/a | |
---|
87 | n/a | |
---|
88 | n/a | |
---|
89 | n/a | |
---|
90 | n/a | class HTMLNode: |
---|
91 | n/a | """Some of the parser's functionality is separated into this class. |
---|
92 | n/a | |
---|
93 | n/a | A Node accumulates its contents, takes care of links to other Nodes |
---|
94 | n/a | and saves itself when it is finished and all links are resolved. |
---|
95 | n/a | """ |
---|
96 | n/a | |
---|
97 | n/a | DOCTYPE = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">' |
---|
98 | n/a | |
---|
99 | n/a | type = 0 |
---|
100 | n/a | cont = '' |
---|
101 | n/a | epilogue = '</BODY></HTML>\n' |
---|
102 | n/a | |
---|
103 | n/a | def __init__(self, dir, name, topname, title, next, prev, up): |
---|
104 | n/a | self.dirname = dir |
---|
105 | n/a | self.name = name |
---|
106 | n/a | if topname: |
---|
107 | n/a | self.topname = topname |
---|
108 | n/a | else: |
---|
109 | n/a | self.topname = name |
---|
110 | n/a | self.title = title |
---|
111 | n/a | self.next = next |
---|
112 | n/a | self.prev = prev |
---|
113 | n/a | self.up = up |
---|
114 | n/a | self.lines = [] |
---|
115 | n/a | |
---|
116 | n/a | def write(self, *lines): |
---|
117 | n/a | for line in lines: |
---|
118 | n/a | self.lines.append(line) |
---|
119 | n/a | |
---|
120 | n/a | def flush(self): |
---|
121 | n/a | fp = open(self.dirname + '/' + makefile(self.name), 'w') |
---|
122 | n/a | fp.write(self.prologue) |
---|
123 | n/a | fp.write(self.text) |
---|
124 | n/a | fp.write(self.epilogue) |
---|
125 | n/a | fp.close() |
---|
126 | n/a | |
---|
127 | n/a | def link(self, label, nodename, rel=None, rev=None): |
---|
128 | n/a | if nodename: |
---|
129 | n/a | if nodename.lower() == '(dir)': |
---|
130 | n/a | addr = '../dir.html' |
---|
131 | n/a | title = '' |
---|
132 | n/a | else: |
---|
133 | n/a | addr = makefile(nodename) |
---|
134 | n/a | title = ' TITLE="%s"' % nodename |
---|
135 | n/a | self.write(label, ': <A HREF="', addr, '"', \ |
---|
136 | n/a | rel and (' REL=' + rel) or "", \ |
---|
137 | n/a | rev and (' REV=' + rev) or "", \ |
---|
138 | n/a | title, '>', nodename, '</A> \n') |
---|
139 | n/a | |
---|
140 | n/a | def finalize(self): |
---|
141 | n/a | length = len(self.lines) |
---|
142 | n/a | self.text = ''.join(self.lines) |
---|
143 | n/a | self.lines = [] |
---|
144 | n/a | self.open_links() |
---|
145 | n/a | self.output_links() |
---|
146 | n/a | self.close_links() |
---|
147 | n/a | links = ''.join(self.lines) |
---|
148 | n/a | self.lines = [] |
---|
149 | n/a | self.prologue = ( |
---|
150 | n/a | self.DOCTYPE + |
---|
151 | n/a | '\n<HTML><HEAD>\n' |
---|
152 | n/a | ' <!-- Converted with texi2html and Python -->\n' |
---|
153 | n/a | ' <TITLE>' + self.title + '</TITLE>\n' |
---|
154 | n/a | ' <LINK REL=Next HREF="' |
---|
155 | n/a | + makefile(self.next) + '" TITLE="' + self.next + '">\n' |
---|
156 | n/a | ' <LINK REL=Previous HREF="' |
---|
157 | n/a | + makefile(self.prev) + '" TITLE="' + self.prev + '">\n' |
---|
158 | n/a | ' <LINK REL=Up HREF="' |
---|
159 | n/a | + makefile(self.up) + '" TITLE="' + self.up + '">\n' |
---|
160 | n/a | '</HEAD><BODY>\n' + |
---|
161 | n/a | links) |
---|
162 | n/a | if length > 20: |
---|
163 | n/a | self.epilogue = '<P>\n%s</BODY></HTML>\n' % links |
---|
164 | n/a | |
---|
165 | n/a | def open_links(self): |
---|
166 | n/a | self.write('<HR>\n') |
---|
167 | n/a | |
---|
168 | n/a | def close_links(self): |
---|
169 | n/a | self.write('<HR>\n') |
---|
170 | n/a | |
---|
171 | n/a | def output_links(self): |
---|
172 | n/a | if self.cont != self.next: |
---|
173 | n/a | self.link(' Cont', self.cont) |
---|
174 | n/a | self.link(' Next', self.next, rel='Next') |
---|
175 | n/a | self.link(' Prev', self.prev, rel='Previous') |
---|
176 | n/a | self.link(' Up', self.up, rel='Up') |
---|
177 | n/a | if self.name != self.topname: |
---|
178 | n/a | self.link(' Top', self.topname) |
---|
179 | n/a | |
---|
180 | n/a | |
---|
181 | n/a | class HTML3Node(HTMLNode): |
---|
182 | n/a | |
---|
183 | n/a | DOCTYPE = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML Level 3//EN//3.0">' |
---|
184 | n/a | |
---|
185 | n/a | def open_links(self): |
---|
186 | n/a | self.write('<DIV CLASS=Navigation>\n <HR>\n') |
---|
187 | n/a | |
---|
188 | n/a | def close_links(self): |
---|
189 | n/a | self.write(' <HR>\n</DIV>\n') |
---|
190 | n/a | |
---|
191 | n/a | |
---|
192 | n/a | class TexinfoParser: |
---|
193 | n/a | |
---|
194 | n/a | COPYRIGHT_SYMBOL = "©" |
---|
195 | n/a | FN_ID_PATTERN = "(%(id)s)" |
---|
196 | n/a | FN_SOURCE_PATTERN = '<A NAME=footnoteref%(id)s' \ |
---|
197 | n/a | ' HREF="#footnotetext%(id)s">' \ |
---|
198 | n/a | + FN_ID_PATTERN + '</A>' |
---|
199 | n/a | FN_TARGET_PATTERN = '<A NAME=footnotetext%(id)s' \ |
---|
200 | n/a | ' HREF="#footnoteref%(id)s">' \ |
---|
201 | n/a | + FN_ID_PATTERN + '</A>\n%(text)s<P>\n' |
---|
202 | n/a | FN_HEADER = '\n<P>\n<HR NOSHADE SIZE=1 WIDTH=200>\n' \ |
---|
203 | n/a | '<STRONG><EM>Footnotes</EM></STRONG>\n<P>' |
---|
204 | n/a | |
---|
205 | n/a | |
---|
206 | n/a | Node = HTMLNode |
---|
207 | n/a | |
---|
208 | n/a | # Initialize an instance |
---|
209 | n/a | def __init__(self): |
---|
210 | n/a | self.unknown = {} # statistics about unknown @-commands |
---|
211 | n/a | self.filenames = {} # Check for identical filenames |
---|
212 | n/a | self.debugging = 0 # larger values produce more output |
---|
213 | n/a | self.print_headers = 0 # always print headers? |
---|
214 | n/a | self.nodefp = None # open file we're writing to |
---|
215 | n/a | self.nodelineno = 0 # Linenumber relative to node |
---|
216 | n/a | self.links = None # Links from current node |
---|
217 | n/a | self.savetext = None # If not None, save text head instead |
---|
218 | n/a | self.savestack = [] # If not None, save text head instead |
---|
219 | n/a | self.htmlhelp = None # html help data |
---|
220 | n/a | self.dirname = 'tmp' # directory where files are created |
---|
221 | n/a | self.includedir = '.' # directory to search @include files |
---|
222 | n/a | self.nodename = '' # name of current node |
---|
223 | n/a | self.topname = '' # name of top node (first node seen) |
---|
224 | n/a | self.title = '' # title of this whole Texinfo tree |
---|
225 | n/a | self.resetindex() # Reset all indices |
---|
226 | n/a | self.contents = [] # Reset table of contents |
---|
227 | n/a | self.numbering = [] # Reset section numbering counters |
---|
228 | n/a | self.nofill = 0 # Normal operation: fill paragraphs |
---|
229 | n/a | self.values={'html': 1} # Names that should be parsed in ifset |
---|
230 | n/a | self.stackinfo={} # Keep track of state in the stack |
---|
231 | n/a | # XXX The following should be reset per node?! |
---|
232 | n/a | self.footnotes = [] # Reset list of footnotes |
---|
233 | n/a | self.itemarg = None # Reset command used by @item |
---|
234 | n/a | self.itemnumber = None # Reset number for @item in @enumerate |
---|
235 | n/a | self.itemindex = None # Reset item index name |
---|
236 | n/a | self.node = None |
---|
237 | n/a | self.nodestack = [] |
---|
238 | n/a | self.cont = 0 |
---|
239 | n/a | self.includedepth = 0 |
---|
240 | n/a | |
---|
241 | n/a | # Set htmlhelp helper class |
---|
242 | n/a | def sethtmlhelp(self, htmlhelp): |
---|
243 | n/a | self.htmlhelp = htmlhelp |
---|
244 | n/a | |
---|
245 | n/a | # Set (output) directory name |
---|
246 | n/a | def setdirname(self, dirname): |
---|
247 | n/a | self.dirname = dirname |
---|
248 | n/a | |
---|
249 | n/a | # Set include directory name |
---|
250 | n/a | def setincludedir(self, includedir): |
---|
251 | n/a | self.includedir = includedir |
---|
252 | n/a | |
---|
253 | n/a | # Parse the contents of an entire file |
---|
254 | n/a | def parse(self, fp): |
---|
255 | n/a | line = fp.readline() |
---|
256 | n/a | lineno = 1 |
---|
257 | n/a | while line and (line[0] == '%' or blprog.match(line)): |
---|
258 | n/a | line = fp.readline() |
---|
259 | n/a | lineno = lineno + 1 |
---|
260 | n/a | if line[:len(MAGIC)] != MAGIC: |
---|
261 | n/a | raise SyntaxError('file does not begin with %r' % (MAGIC,)) |
---|
262 | n/a | self.parserest(fp, lineno) |
---|
263 | n/a | |
---|
264 | n/a | # Parse the contents of a file, not expecting a MAGIC header |
---|
265 | n/a | def parserest(self, fp, initial_lineno): |
---|
266 | n/a | lineno = initial_lineno |
---|
267 | n/a | self.done = 0 |
---|
268 | n/a | self.skip = 0 |
---|
269 | n/a | self.stack = [] |
---|
270 | n/a | accu = [] |
---|
271 | n/a | while not self.done: |
---|
272 | n/a | line = fp.readline() |
---|
273 | n/a | self.nodelineno = self.nodelineno + 1 |
---|
274 | n/a | if not line: |
---|
275 | n/a | if accu: |
---|
276 | n/a | if not self.skip: self.process(accu) |
---|
277 | n/a | accu = [] |
---|
278 | n/a | if initial_lineno > 0: |
---|
279 | n/a | print('*** EOF before @bye') |
---|
280 | n/a | break |
---|
281 | n/a | lineno = lineno + 1 |
---|
282 | n/a | mo = cmprog.match(line) |
---|
283 | n/a | if mo: |
---|
284 | n/a | a, b = mo.span(1) |
---|
285 | n/a | cmd = line[a:b] |
---|
286 | n/a | if cmd in ('noindent', 'refill'): |
---|
287 | n/a | accu.append(line) |
---|
288 | n/a | else: |
---|
289 | n/a | if accu: |
---|
290 | n/a | if not self.skip: |
---|
291 | n/a | self.process(accu) |
---|
292 | n/a | accu = [] |
---|
293 | n/a | self.command(line, mo) |
---|
294 | n/a | elif blprog.match(line) and \ |
---|
295 | n/a | 'format' not in self.stack and \ |
---|
296 | n/a | 'example' not in self.stack: |
---|
297 | n/a | if accu: |
---|
298 | n/a | if not self.skip: |
---|
299 | n/a | self.process(accu) |
---|
300 | n/a | if self.nofill: |
---|
301 | n/a | self.write('\n') |
---|
302 | n/a | else: |
---|
303 | n/a | self.write('<P>\n') |
---|
304 | n/a | accu = [] |
---|
305 | n/a | else: |
---|
306 | n/a | # Append the line including trailing \n! |
---|
307 | n/a | accu.append(line) |
---|
308 | n/a | # |
---|
309 | n/a | if self.skip: |
---|
310 | n/a | print('*** Still skipping at the end') |
---|
311 | n/a | if self.stack: |
---|
312 | n/a | print('*** Stack not empty at the end') |
---|
313 | n/a | print('***', self.stack) |
---|
314 | n/a | if self.includedepth == 0: |
---|
315 | n/a | while self.nodestack: |
---|
316 | n/a | self.nodestack[-1].finalize() |
---|
317 | n/a | self.nodestack[-1].flush() |
---|
318 | n/a | del self.nodestack[-1] |
---|
319 | n/a | |
---|
320 | n/a | # Start saving text in a buffer instead of writing it to a file |
---|
321 | n/a | def startsaving(self): |
---|
322 | n/a | if self.savetext is not None: |
---|
323 | n/a | self.savestack.append(self.savetext) |
---|
324 | n/a | # print '*** Recursively saving text, expect trouble' |
---|
325 | n/a | self.savetext = '' |
---|
326 | n/a | |
---|
327 | n/a | # Return the text saved so far and start writing to file again |
---|
328 | n/a | def collectsavings(self): |
---|
329 | n/a | savetext = self.savetext |
---|
330 | n/a | if len(self.savestack) > 0: |
---|
331 | n/a | self.savetext = self.savestack[-1] |
---|
332 | n/a | del self.savestack[-1] |
---|
333 | n/a | else: |
---|
334 | n/a | self.savetext = None |
---|
335 | n/a | return savetext or '' |
---|
336 | n/a | |
---|
337 | n/a | # Write text to file, or save it in a buffer, or ignore it |
---|
338 | n/a | def write(self, *args): |
---|
339 | n/a | try: |
---|
340 | n/a | text = ''.join(args) |
---|
341 | n/a | except: |
---|
342 | n/a | print(args) |
---|
343 | n/a | raise TypeError |
---|
344 | n/a | if self.savetext is not None: |
---|
345 | n/a | self.savetext = self.savetext + text |
---|
346 | n/a | elif self.nodefp: |
---|
347 | n/a | self.nodefp.write(text) |
---|
348 | n/a | elif self.node: |
---|
349 | n/a | self.node.write(text) |
---|
350 | n/a | |
---|
351 | n/a | # Complete the current node -- write footnotes and close file |
---|
352 | n/a | def endnode(self): |
---|
353 | n/a | if self.savetext is not None: |
---|
354 | n/a | print('*** Still saving text at end of node') |
---|
355 | n/a | dummy = self.collectsavings() |
---|
356 | n/a | if self.footnotes: |
---|
357 | n/a | self.writefootnotes() |
---|
358 | n/a | if self.nodefp: |
---|
359 | n/a | if self.nodelineno > 20: |
---|
360 | n/a | self.write('<HR>\n') |
---|
361 | n/a | [name, next, prev, up] = self.nodelinks[:4] |
---|
362 | n/a | self.link('Next', next) |
---|
363 | n/a | self.link('Prev', prev) |
---|
364 | n/a | self.link('Up', up) |
---|
365 | n/a | if self.nodename != self.topname: |
---|
366 | n/a | self.link('Top', self.topname) |
---|
367 | n/a | self.write('<HR>\n') |
---|
368 | n/a | self.write('</BODY>\n') |
---|
369 | n/a | self.nodefp.close() |
---|
370 | n/a | self.nodefp = None |
---|
371 | n/a | elif self.node: |
---|
372 | n/a | if not self.cont and \ |
---|
373 | n/a | (not self.node.type or \ |
---|
374 | n/a | (self.node.next and self.node.prev and self.node.up)): |
---|
375 | n/a | self.node.finalize() |
---|
376 | n/a | self.node.flush() |
---|
377 | n/a | else: |
---|
378 | n/a | self.nodestack.append(self.node) |
---|
379 | n/a | self.node = None |
---|
380 | n/a | self.nodename = '' |
---|
381 | n/a | |
---|
382 | n/a | # Process a list of lines, expanding embedded @-commands |
---|
383 | n/a | # This mostly distinguishes between menus and normal text |
---|
384 | n/a | def process(self, accu): |
---|
385 | n/a | if self.debugging > 1: |
---|
386 | n/a | print('!'*self.debugging, 'process:', self.skip, self.stack, end=' ') |
---|
387 | n/a | if accu: print(accu[0][:30], end=' ') |
---|
388 | n/a | if accu[0][30:] or accu[1:]: print('...', end=' ') |
---|
389 | n/a | print() |
---|
390 | n/a | if self.inmenu(): |
---|
391 | n/a | # XXX should be done differently |
---|
392 | n/a | for line in accu: |
---|
393 | n/a | mo = miprog.match(line) |
---|
394 | n/a | if not mo: |
---|
395 | n/a | line = line.strip() + '\n' |
---|
396 | n/a | self.expand(line) |
---|
397 | n/a | continue |
---|
398 | n/a | bgn, end = mo.span(0) |
---|
399 | n/a | a, b = mo.span(1) |
---|
400 | n/a | c, d = mo.span(2) |
---|
401 | n/a | e, f = mo.span(3) |
---|
402 | n/a | g, h = mo.span(4) |
---|
403 | n/a | label = line[a:b] |
---|
404 | n/a | nodename = line[c:d] |
---|
405 | n/a | if nodename[0] == ':': nodename = label |
---|
406 | n/a | else: nodename = line[e:f] |
---|
407 | n/a | punct = line[g:h] |
---|
408 | n/a | self.write(' <LI><A HREF="', |
---|
409 | n/a | makefile(nodename), |
---|
410 | n/a | '">', nodename, |
---|
411 | n/a | '</A>', punct, '\n') |
---|
412 | n/a | self.htmlhelp.menuitem(nodename) |
---|
413 | n/a | self.expand(line[end:]) |
---|
414 | n/a | else: |
---|
415 | n/a | text = ''.join(accu) |
---|
416 | n/a | self.expand(text) |
---|
417 | n/a | |
---|
418 | n/a | # find 'menu' (we might be inside 'ifset' or 'ifclear') |
---|
419 | n/a | def inmenu(self): |
---|
420 | n/a | #if 'menu' in self.stack: |
---|
421 | n/a | # print 'inmenu :', self.skip, self.stack, self.stackinfo |
---|
422 | n/a | stack = self.stack |
---|
423 | n/a | while stack and stack[-1] in ('ifset','ifclear'): |
---|
424 | n/a | try: |
---|
425 | n/a | if self.stackinfo[len(stack)]: |
---|
426 | n/a | return 0 |
---|
427 | n/a | except KeyError: |
---|
428 | n/a | pass |
---|
429 | n/a | stack = stack[:-1] |
---|
430 | n/a | return (stack and stack[-1] == 'menu') |
---|
431 | n/a | |
---|
432 | n/a | # Write a string, expanding embedded @-commands |
---|
433 | n/a | def expand(self, text): |
---|
434 | n/a | stack = [] |
---|
435 | n/a | i = 0 |
---|
436 | n/a | n = len(text) |
---|
437 | n/a | while i < n: |
---|
438 | n/a | start = i |
---|
439 | n/a | mo = spprog.search(text, i) |
---|
440 | n/a | if mo: |
---|
441 | n/a | i = mo.start() |
---|
442 | n/a | else: |
---|
443 | n/a | self.write(text[start:]) |
---|
444 | n/a | break |
---|
445 | n/a | self.write(text[start:i]) |
---|
446 | n/a | c = text[i] |
---|
447 | n/a | i = i+1 |
---|
448 | n/a | if c == '\n': |
---|
449 | n/a | self.write('\n') |
---|
450 | n/a | continue |
---|
451 | n/a | if c == '<': |
---|
452 | n/a | self.write('<') |
---|
453 | n/a | continue |
---|
454 | n/a | if c == '>': |
---|
455 | n/a | self.write('>') |
---|
456 | n/a | continue |
---|
457 | n/a | if c == '&': |
---|
458 | n/a | self.write('&') |
---|
459 | n/a | continue |
---|
460 | n/a | if c == '{': |
---|
461 | n/a | stack.append('') |
---|
462 | n/a | continue |
---|
463 | n/a | if c == '}': |
---|
464 | n/a | if not stack: |
---|
465 | n/a | print('*** Unmatched }') |
---|
466 | n/a | self.write('}') |
---|
467 | n/a | continue |
---|
468 | n/a | cmd = stack[-1] |
---|
469 | n/a | del stack[-1] |
---|
470 | n/a | try: |
---|
471 | n/a | method = getattr(self, 'close_' + cmd) |
---|
472 | n/a | except AttributeError: |
---|
473 | n/a | self.unknown_close(cmd) |
---|
474 | n/a | continue |
---|
475 | n/a | method() |
---|
476 | n/a | continue |
---|
477 | n/a | if c != '@': |
---|
478 | n/a | # Cannot happen unless spprog is changed |
---|
479 | n/a | raise RuntimeError('unexpected funny %r' % c) |
---|
480 | n/a | start = i |
---|
481 | n/a | while i < n and text[i] in string.ascii_letters: i = i+1 |
---|
482 | n/a | if i == start: |
---|
483 | n/a | # @ plus non-letter: literal next character |
---|
484 | n/a | i = i+1 |
---|
485 | n/a | c = text[start:i] |
---|
486 | n/a | if c == ':': |
---|
487 | n/a | # `@:' means no extra space after |
---|
488 | n/a | # preceding `.', `?', `!' or `:' |
---|
489 | n/a | pass |
---|
490 | n/a | else: |
---|
491 | n/a | # `@.' means a sentence-ending period; |
---|
492 | n/a | # `@@', `@{', `@}' quote `@', `{', `}' |
---|
493 | n/a | self.write(c) |
---|
494 | n/a | continue |
---|
495 | n/a | cmd = text[start:i] |
---|
496 | n/a | if i < n and text[i] == '{': |
---|
497 | n/a | i = i+1 |
---|
498 | n/a | stack.append(cmd) |
---|
499 | n/a | try: |
---|
500 | n/a | method = getattr(self, 'open_' + cmd) |
---|
501 | n/a | except AttributeError: |
---|
502 | n/a | self.unknown_open(cmd) |
---|
503 | n/a | continue |
---|
504 | n/a | method() |
---|
505 | n/a | continue |
---|
506 | n/a | try: |
---|
507 | n/a | method = getattr(self, 'handle_' + cmd) |
---|
508 | n/a | except AttributeError: |
---|
509 | n/a | self.unknown_handle(cmd) |
---|
510 | n/a | continue |
---|
511 | n/a | method() |
---|
512 | n/a | if stack: |
---|
513 | n/a | print('*** Stack not empty at para:', stack) |
---|
514 | n/a | |
---|
515 | n/a | # --- Handle unknown embedded @-commands --- |
---|
516 | n/a | |
---|
517 | n/a | def unknown_open(self, cmd): |
---|
518 | n/a | print('*** No open func for @' + cmd + '{...}') |
---|
519 | n/a | cmd = cmd + '{' |
---|
520 | n/a | self.write('@', cmd) |
---|
521 | n/a | if cmd not in self.unknown: |
---|
522 | n/a | self.unknown[cmd] = 1 |
---|
523 | n/a | else: |
---|
524 | n/a | self.unknown[cmd] = self.unknown[cmd] + 1 |
---|
525 | n/a | |
---|
526 | n/a | def unknown_close(self, cmd): |
---|
527 | n/a | print('*** No close func for @' + cmd + '{...}') |
---|
528 | n/a | cmd = '}' + cmd |
---|
529 | n/a | self.write('}') |
---|
530 | n/a | if cmd not in self.unknown: |
---|
531 | n/a | self.unknown[cmd] = 1 |
---|
532 | n/a | else: |
---|
533 | n/a | self.unknown[cmd] = self.unknown[cmd] + 1 |
---|
534 | n/a | |
---|
535 | n/a | def unknown_handle(self, cmd): |
---|
536 | n/a | print('*** No handler for @' + cmd) |
---|
537 | n/a | self.write('@', cmd) |
---|
538 | n/a | if cmd not in self.unknown: |
---|
539 | n/a | self.unknown[cmd] = 1 |
---|
540 | n/a | else: |
---|
541 | n/a | self.unknown[cmd] = self.unknown[cmd] + 1 |
---|
542 | n/a | |
---|
543 | n/a | # XXX The following sections should be ordered as the texinfo docs |
---|
544 | n/a | |
---|
545 | n/a | # --- Embedded @-commands without {} argument list -- |
---|
546 | n/a | |
---|
547 | n/a | def handle_noindent(self): pass |
---|
548 | n/a | |
---|
549 | n/a | def handle_refill(self): pass |
---|
550 | n/a | |
---|
551 | n/a | # --- Include file handling --- |
---|
552 | n/a | |
---|
553 | n/a | def do_include(self, args): |
---|
554 | n/a | file = args |
---|
555 | n/a | file = os.path.join(self.includedir, file) |
---|
556 | n/a | try: |
---|
557 | n/a | fp = open(file, 'r') |
---|
558 | n/a | except IOError as msg: |
---|
559 | n/a | print('*** Can\'t open include file', repr(file)) |
---|
560 | n/a | return |
---|
561 | n/a | print('!'*self.debugging, '--> file', repr(file)) |
---|
562 | n/a | save_done = self.done |
---|
563 | n/a | save_skip = self.skip |
---|
564 | n/a | save_stack = self.stack |
---|
565 | n/a | self.includedepth = self.includedepth + 1 |
---|
566 | n/a | self.parserest(fp, 0) |
---|
567 | n/a | self.includedepth = self.includedepth - 1 |
---|
568 | n/a | fp.close() |
---|
569 | n/a | self.done = save_done |
---|
570 | n/a | self.skip = save_skip |
---|
571 | n/a | self.stack = save_stack |
---|
572 | n/a | print('!'*self.debugging, '<-- file', repr(file)) |
---|
573 | n/a | |
---|
574 | n/a | # --- Special Insertions --- |
---|
575 | n/a | |
---|
576 | n/a | def open_dmn(self): pass |
---|
577 | n/a | def close_dmn(self): pass |
---|
578 | n/a | |
---|
579 | n/a | def open_dots(self): self.write('...') |
---|
580 | n/a | def close_dots(self): pass |
---|
581 | n/a | |
---|
582 | n/a | def open_bullet(self): pass |
---|
583 | n/a | def close_bullet(self): pass |
---|
584 | n/a | |
---|
585 | n/a | def open_TeX(self): self.write('TeX') |
---|
586 | n/a | def close_TeX(self): pass |
---|
587 | n/a | |
---|
588 | n/a | def handle_copyright(self): self.write(self.COPYRIGHT_SYMBOL) |
---|
589 | n/a | def open_copyright(self): self.write(self.COPYRIGHT_SYMBOL) |
---|
590 | n/a | def close_copyright(self): pass |
---|
591 | n/a | |
---|
592 | n/a | def open_minus(self): self.write('-') |
---|
593 | n/a | def close_minus(self): pass |
---|
594 | n/a | |
---|
595 | n/a | # --- Accents --- |
---|
596 | n/a | |
---|
597 | n/a | # rpyron 2002-05-07 |
---|
598 | n/a | # I would like to do at least as well as makeinfo when |
---|
599 | n/a | # it is producing HTML output: |
---|
600 | n/a | # |
---|
601 | n/a | # input output |
---|
602 | n/a | # @"o @"o umlaut accent |
---|
603 | n/a | # @'o 'o acute accent |
---|
604 | n/a | # @,{c} @,{c} cedilla accent |
---|
605 | n/a | # @=o @=o macron/overbar accent |
---|
606 | n/a | # @^o @^o circumflex accent |
---|
607 | n/a | # @`o `o grave accent |
---|
608 | n/a | # @~o @~o tilde accent |
---|
609 | n/a | # @dotaccent{o} @dotaccent{o} overdot accent |
---|
610 | n/a | # @H{o} @H{o} long Hungarian umlaut |
---|
611 | n/a | # @ringaccent{o} @ringaccent{o} ring accent |
---|
612 | n/a | # @tieaccent{oo} @tieaccent{oo} tie-after accent |
---|
613 | n/a | # @u{o} @u{o} breve accent |
---|
614 | n/a | # @ubaraccent{o} @ubaraccent{o} underbar accent |
---|
615 | n/a | # @udotaccent{o} @udotaccent{o} underdot accent |
---|
616 | n/a | # @v{o} @v{o} hacek or check accent |
---|
617 | n/a | # @exclamdown{} ¡ upside-down ! |
---|
618 | n/a | # @questiondown{} ¿ upside-down ? |
---|
619 | n/a | # @aa{},@AA{} å,Å a,A with circle |
---|
620 | n/a | # @ae{},@AE{} æ,Æ ae,AE ligatures |
---|
621 | n/a | # @dotless{i} @dotless{i} dotless i |
---|
622 | n/a | # @dotless{j} @dotless{j} dotless j |
---|
623 | n/a | # @l{},@L{} l/,L/ suppressed-L,l |
---|
624 | n/a | # @o{},@O{} ø,Ø O,o with slash |
---|
625 | n/a | # @oe{},@OE{} oe,OE oe,OE ligatures |
---|
626 | n/a | # @ss{} ß es-zet or sharp S |
---|
627 | n/a | # |
---|
628 | n/a | # The following character codes and approximations have been |
---|
629 | n/a | # copied from makeinfo's HTML output. |
---|
630 | n/a | |
---|
631 | n/a | def open_exclamdown(self): self.write('¡') # upside-down ! |
---|
632 | n/a | def close_exclamdown(self): pass |
---|
633 | n/a | def open_questiondown(self): self.write('¿') # upside-down ? |
---|
634 | n/a | def close_questiondown(self): pass |
---|
635 | n/a | def open_aa(self): self.write('å') # a with circle |
---|
636 | n/a | def close_aa(self): pass |
---|
637 | n/a | def open_AA(self): self.write('Å') # A with circle |
---|
638 | n/a | def close_AA(self): pass |
---|
639 | n/a | def open_ae(self): self.write('æ') # ae ligatures |
---|
640 | n/a | def close_ae(self): pass |
---|
641 | n/a | def open_AE(self): self.write('Æ') # AE ligatures |
---|
642 | n/a | def close_AE(self): pass |
---|
643 | n/a | def open_o(self): self.write('ø') # o with slash |
---|
644 | n/a | def close_o(self): pass |
---|
645 | n/a | def open_O(self): self.write('Ø') # O with slash |
---|
646 | n/a | def close_O(self): pass |
---|
647 | n/a | def open_ss(self): self.write('ß') # es-zet or sharp S |
---|
648 | n/a | def close_ss(self): pass |
---|
649 | n/a | def open_oe(self): self.write('oe') # oe ligatures |
---|
650 | n/a | def close_oe(self): pass |
---|
651 | n/a | def open_OE(self): self.write('OE') # OE ligatures |
---|
652 | n/a | def close_OE(self): pass |
---|
653 | n/a | def open_l(self): self.write('l/') # suppressed-l |
---|
654 | n/a | def close_l(self): pass |
---|
655 | n/a | def open_L(self): self.write('L/') # suppressed-L |
---|
656 | n/a | def close_L(self): pass |
---|
657 | n/a | |
---|
658 | n/a | # --- Special Glyphs for Examples --- |
---|
659 | n/a | |
---|
660 | n/a | def open_result(self): self.write('=>') |
---|
661 | n/a | def close_result(self): pass |
---|
662 | n/a | |
---|
663 | n/a | def open_expansion(self): self.write('==>') |
---|
664 | n/a | def close_expansion(self): pass |
---|
665 | n/a | |
---|
666 | n/a | def open_print(self): self.write('-|') |
---|
667 | n/a | def close_print(self): pass |
---|
668 | n/a | |
---|
669 | n/a | def open_error(self): self.write('error-->') |
---|
670 | n/a | def close_error(self): pass |
---|
671 | n/a | |
---|
672 | n/a | def open_equiv(self): self.write('==') |
---|
673 | n/a | def close_equiv(self): pass |
---|
674 | n/a | |
---|
675 | n/a | def open_point(self): self.write('-!-') |
---|
676 | n/a | def close_point(self): pass |
---|
677 | n/a | |
---|
678 | n/a | # --- Cross References --- |
---|
679 | n/a | |
---|
680 | n/a | def open_pxref(self): |
---|
681 | n/a | self.write('see ') |
---|
682 | n/a | self.startsaving() |
---|
683 | n/a | def close_pxref(self): |
---|
684 | n/a | self.makeref() |
---|
685 | n/a | |
---|
686 | n/a | def open_xref(self): |
---|
687 | n/a | self.write('See ') |
---|
688 | n/a | self.startsaving() |
---|
689 | n/a | def close_xref(self): |
---|
690 | n/a | self.makeref() |
---|
691 | n/a | |
---|
692 | n/a | def open_ref(self): |
---|
693 | n/a | self.startsaving() |
---|
694 | n/a | def close_ref(self): |
---|
695 | n/a | self.makeref() |
---|
696 | n/a | |
---|
697 | n/a | def open_inforef(self): |
---|
698 | n/a | self.write('See info file ') |
---|
699 | n/a | self.startsaving() |
---|
700 | n/a | def close_inforef(self): |
---|
701 | n/a | text = self.collectsavings() |
---|
702 | n/a | args = [s.strip() for s in text.split(',')] |
---|
703 | n/a | while len(args) < 3: args.append('') |
---|
704 | n/a | node = args[0] |
---|
705 | n/a | file = args[2] |
---|
706 | n/a | self.write('`', file, '\', node `', node, '\'') |
---|
707 | n/a | |
---|
708 | n/a | def makeref(self): |
---|
709 | n/a | text = self.collectsavings() |
---|
710 | n/a | args = [s.strip() for s in text.split(',')] |
---|
711 | n/a | while len(args) < 5: args.append('') |
---|
712 | n/a | nodename = label = args[0] |
---|
713 | n/a | if args[2]: label = args[2] |
---|
714 | n/a | file = args[3] |
---|
715 | n/a | title = args[4] |
---|
716 | n/a | href = makefile(nodename) |
---|
717 | n/a | if file: |
---|
718 | n/a | href = '../' + file + '/' + href |
---|
719 | n/a | self.write('<A HREF="', href, '">', label, '</A>') |
---|
720 | n/a | |
---|
721 | n/a | # rpyron 2002-05-07 uref support |
---|
722 | n/a | def open_uref(self): |
---|
723 | n/a | self.startsaving() |
---|
724 | n/a | def close_uref(self): |
---|
725 | n/a | text = self.collectsavings() |
---|
726 | n/a | args = [s.strip() for s in text.split(',')] |
---|
727 | n/a | while len(args) < 2: args.append('') |
---|
728 | n/a | href = args[0] |
---|
729 | n/a | label = args[1] |
---|
730 | n/a | if not label: label = href |
---|
731 | n/a | self.write('<A HREF="', href, '">', label, '</A>') |
---|
732 | n/a | |
---|
733 | n/a | # rpyron 2002-05-07 image support |
---|
734 | n/a | # GNU makeinfo producing HTML output tries `filename.png'; if |
---|
735 | n/a | # that does not exist, it tries `filename.jpg'. If that does |
---|
736 | n/a | # not exist either, it complains. GNU makeinfo does not handle |
---|
737 | n/a | # GIF files; however, I include GIF support here because |
---|
738 | n/a | # MySQL documentation uses GIF files. |
---|
739 | n/a | |
---|
740 | n/a | def open_image(self): |
---|
741 | n/a | self.startsaving() |
---|
742 | n/a | def close_image(self): |
---|
743 | n/a | self.makeimage() |
---|
744 | n/a | def makeimage(self): |
---|
745 | n/a | text = self.collectsavings() |
---|
746 | n/a | args = [s.strip() for s in text.split(',')] |
---|
747 | n/a | while len(args) < 5: args.append('') |
---|
748 | n/a | filename = args[0] |
---|
749 | n/a | width = args[1] |
---|
750 | n/a | height = args[2] |
---|
751 | n/a | alt = args[3] |
---|
752 | n/a | ext = args[4] |
---|
753 | n/a | |
---|
754 | n/a | # The HTML output will have a reference to the image |
---|
755 | n/a | # that is relative to the HTML output directory, |
---|
756 | n/a | # which is what 'filename' gives us. However, we need |
---|
757 | n/a | # to find it relative to our own current directory, |
---|
758 | n/a | # so we construct 'imagename'. |
---|
759 | n/a | imagelocation = self.dirname + '/' + filename |
---|
760 | n/a | |
---|
761 | n/a | if os.path.exists(imagelocation+'.png'): |
---|
762 | n/a | filename += '.png' |
---|
763 | n/a | elif os.path.exists(imagelocation+'.jpg'): |
---|
764 | n/a | filename += '.jpg' |
---|
765 | n/a | elif os.path.exists(imagelocation+'.gif'): # MySQL uses GIF files |
---|
766 | n/a | filename += '.gif' |
---|
767 | n/a | else: |
---|
768 | n/a | print("*** Cannot find image " + imagelocation) |
---|
769 | n/a | #TODO: what is 'ext'? |
---|
770 | n/a | self.write('<IMG SRC="', filename, '"', \ |
---|
771 | n/a | width and (' WIDTH="' + width + '"') or "", \ |
---|
772 | n/a | height and (' HEIGHT="' + height + '"') or "", \ |
---|
773 | n/a | alt and (' ALT="' + alt + '"') or "", \ |
---|
774 | n/a | '/>' ) |
---|
775 | n/a | self.htmlhelp.addimage(imagelocation) |
---|
776 | n/a | |
---|
777 | n/a | |
---|
778 | n/a | # --- Marking Words and Phrases --- |
---|
779 | n/a | |
---|
780 | n/a | # --- Other @xxx{...} commands --- |
---|
781 | n/a | |
---|
782 | n/a | def open_(self): pass # Used by {text enclosed in braces} |
---|
783 | n/a | def close_(self): pass |
---|
784 | n/a | |
---|
785 | n/a | open_asis = open_ |
---|
786 | n/a | close_asis = close_ |
---|
787 | n/a | |
---|
788 | n/a | def open_cite(self): self.write('<CITE>') |
---|
789 | n/a | def close_cite(self): self.write('</CITE>') |
---|
790 | n/a | |
---|
791 | n/a | def open_code(self): self.write('<CODE>') |
---|
792 | n/a | def close_code(self): self.write('</CODE>') |
---|
793 | n/a | |
---|
794 | n/a | def open_t(self): self.write('<TT>') |
---|
795 | n/a | def close_t(self): self.write('</TT>') |
---|
796 | n/a | |
---|
797 | n/a | def open_dfn(self): self.write('<DFN>') |
---|
798 | n/a | def close_dfn(self): self.write('</DFN>') |
---|
799 | n/a | |
---|
800 | n/a | def open_emph(self): self.write('<EM>') |
---|
801 | n/a | def close_emph(self): self.write('</EM>') |
---|
802 | n/a | |
---|
803 | n/a | def open_i(self): self.write('<I>') |
---|
804 | n/a | def close_i(self): self.write('</I>') |
---|
805 | n/a | |
---|
806 | n/a | def open_footnote(self): |
---|
807 | n/a | # if self.savetext is not None: |
---|
808 | n/a | # print '*** Recursive footnote -- expect weirdness' |
---|
809 | n/a | id = len(self.footnotes) + 1 |
---|
810 | n/a | self.write(self.FN_SOURCE_PATTERN % {'id': repr(id)}) |
---|
811 | n/a | self.startsaving() |
---|
812 | n/a | |
---|
813 | n/a | def close_footnote(self): |
---|
814 | n/a | id = len(self.footnotes) + 1 |
---|
815 | n/a | self.footnotes.append((id, self.collectsavings())) |
---|
816 | n/a | |
---|
817 | n/a | def writefootnotes(self): |
---|
818 | n/a | self.write(self.FN_HEADER) |
---|
819 | n/a | for id, text in self.footnotes: |
---|
820 | n/a | self.write(self.FN_TARGET_PATTERN |
---|
821 | n/a | % {'id': repr(id), 'text': text}) |
---|
822 | n/a | self.footnotes = [] |
---|
823 | n/a | |
---|
824 | n/a | def open_file(self): self.write('<CODE>') |
---|
825 | n/a | def close_file(self): self.write('</CODE>') |
---|
826 | n/a | |
---|
827 | n/a | def open_kbd(self): self.write('<KBD>') |
---|
828 | n/a | def close_kbd(self): self.write('</KBD>') |
---|
829 | n/a | |
---|
830 | n/a | def open_key(self): self.write('<KEY>') |
---|
831 | n/a | def close_key(self): self.write('</KEY>') |
---|
832 | n/a | |
---|
833 | n/a | def open_r(self): self.write('<R>') |
---|
834 | n/a | def close_r(self): self.write('</R>') |
---|
835 | n/a | |
---|
836 | n/a | def open_samp(self): self.write('`<SAMP>') |
---|
837 | n/a | def close_samp(self): self.write('</SAMP>\'') |
---|
838 | n/a | |
---|
839 | n/a | def open_sc(self): self.write('<SMALLCAPS>') |
---|
840 | n/a | def close_sc(self): self.write('</SMALLCAPS>') |
---|
841 | n/a | |
---|
842 | n/a | def open_strong(self): self.write('<STRONG>') |
---|
843 | n/a | def close_strong(self): self.write('</STRONG>') |
---|
844 | n/a | |
---|
845 | n/a | def open_b(self): self.write('<B>') |
---|
846 | n/a | def close_b(self): self.write('</B>') |
---|
847 | n/a | |
---|
848 | n/a | def open_var(self): self.write('<VAR>') |
---|
849 | n/a | def close_var(self): self.write('</VAR>') |
---|
850 | n/a | |
---|
851 | n/a | def open_w(self): self.write('<NOBREAK>') |
---|
852 | n/a | def close_w(self): self.write('</NOBREAK>') |
---|
853 | n/a | |
---|
854 | n/a | def open_url(self): self.startsaving() |
---|
855 | n/a | def close_url(self): |
---|
856 | n/a | text = self.collectsavings() |
---|
857 | n/a | self.write('<A HREF="', text, '">', text, '</A>') |
---|
858 | n/a | |
---|
859 | n/a | def open_email(self): self.startsaving() |
---|
860 | n/a | def close_email(self): |
---|
861 | n/a | text = self.collectsavings() |
---|
862 | n/a | self.write('<A HREF="mailto:', text, '">', text, '</A>') |
---|
863 | n/a | |
---|
864 | n/a | open_titlefont = open_ |
---|
865 | n/a | close_titlefont = close_ |
---|
866 | n/a | |
---|
867 | n/a | def open_small(self): pass |
---|
868 | n/a | def close_small(self): pass |
---|
869 | n/a | |
---|
870 | n/a | def command(self, line, mo): |
---|
871 | n/a | a, b = mo.span(1) |
---|
872 | n/a | cmd = line[a:b] |
---|
873 | n/a | args = line[b:].strip() |
---|
874 | n/a | if self.debugging > 1: |
---|
875 | n/a | print('!'*self.debugging, 'command:', self.skip, self.stack, \ |
---|
876 | n/a | '@' + cmd, args) |
---|
877 | n/a | try: |
---|
878 | n/a | func = getattr(self, 'do_' + cmd) |
---|
879 | n/a | except AttributeError: |
---|
880 | n/a | try: |
---|
881 | n/a | func = getattr(self, 'bgn_' + cmd) |
---|
882 | n/a | except AttributeError: |
---|
883 | n/a | # don't complain if we are skipping anyway |
---|
884 | n/a | if not self.skip: |
---|
885 | n/a | self.unknown_cmd(cmd, args) |
---|
886 | n/a | return |
---|
887 | n/a | self.stack.append(cmd) |
---|
888 | n/a | func(args) |
---|
889 | n/a | return |
---|
890 | n/a | if not self.skip or cmd == 'end': |
---|
891 | n/a | func(args) |
---|
892 | n/a | |
---|
893 | n/a | def unknown_cmd(self, cmd, args): |
---|
894 | n/a | print('*** unknown', '@' + cmd, args) |
---|
895 | n/a | if cmd not in self.unknown: |
---|
896 | n/a | self.unknown[cmd] = 1 |
---|
897 | n/a | else: |
---|
898 | n/a | self.unknown[cmd] = self.unknown[cmd] + 1 |
---|
899 | n/a | |
---|
900 | n/a | def do_end(self, args): |
---|
901 | n/a | words = args.split() |
---|
902 | n/a | if not words: |
---|
903 | n/a | print('*** @end w/o args') |
---|
904 | n/a | else: |
---|
905 | n/a | cmd = words[0] |
---|
906 | n/a | if not self.stack or self.stack[-1] != cmd: |
---|
907 | n/a | print('*** @end', cmd, 'unexpected') |
---|
908 | n/a | else: |
---|
909 | n/a | del self.stack[-1] |
---|
910 | n/a | try: |
---|
911 | n/a | func = getattr(self, 'end_' + cmd) |
---|
912 | n/a | except AttributeError: |
---|
913 | n/a | self.unknown_end(cmd) |
---|
914 | n/a | return |
---|
915 | n/a | func() |
---|
916 | n/a | |
---|
917 | n/a | def unknown_end(self, cmd): |
---|
918 | n/a | cmd = 'end ' + cmd |
---|
919 | n/a | print('*** unknown', '@' + cmd) |
---|
920 | n/a | if cmd not in self.unknown: |
---|
921 | n/a | self.unknown[cmd] = 1 |
---|
922 | n/a | else: |
---|
923 | n/a | self.unknown[cmd] = self.unknown[cmd] + 1 |
---|
924 | n/a | |
---|
925 | n/a | # --- Comments --- |
---|
926 | n/a | |
---|
927 | n/a | def do_comment(self, args): pass |
---|
928 | n/a | do_c = do_comment |
---|
929 | n/a | |
---|
930 | n/a | # --- Conditional processing --- |
---|
931 | n/a | |
---|
932 | n/a | def bgn_ifinfo(self, args): pass |
---|
933 | n/a | def end_ifinfo(self): pass |
---|
934 | n/a | |
---|
935 | n/a | def bgn_iftex(self, args): self.skip = self.skip + 1 |
---|
936 | n/a | def end_iftex(self): self.skip = self.skip - 1 |
---|
937 | n/a | |
---|
938 | n/a | def bgn_ignore(self, args): self.skip = self.skip + 1 |
---|
939 | n/a | def end_ignore(self): self.skip = self.skip - 1 |
---|
940 | n/a | |
---|
941 | n/a | def bgn_tex(self, args): self.skip = self.skip + 1 |
---|
942 | n/a | def end_tex(self): self.skip = self.skip - 1 |
---|
943 | n/a | |
---|
944 | n/a | def do_set(self, args): |
---|
945 | n/a | fields = args.split(' ') |
---|
946 | n/a | key = fields[0] |
---|
947 | n/a | if len(fields) == 1: |
---|
948 | n/a | value = 1 |
---|
949 | n/a | else: |
---|
950 | n/a | value = ' '.join(fields[1:]) |
---|
951 | n/a | self.values[key] = value |
---|
952 | n/a | |
---|
953 | n/a | def do_clear(self, args): |
---|
954 | n/a | self.values[args] = None |
---|
955 | n/a | |
---|
956 | n/a | def bgn_ifset(self, args): |
---|
957 | n/a | if args not in self.values or self.values[args] is None: |
---|
958 | n/a | self.skip = self.skip + 1 |
---|
959 | n/a | self.stackinfo[len(self.stack)] = 1 |
---|
960 | n/a | else: |
---|
961 | n/a | self.stackinfo[len(self.stack)] = 0 |
---|
962 | n/a | def end_ifset(self): |
---|
963 | n/a | try: |
---|
964 | n/a | if self.stackinfo[len(self.stack) + 1]: |
---|
965 | n/a | self.skip = self.skip - 1 |
---|
966 | n/a | del self.stackinfo[len(self.stack) + 1] |
---|
967 | n/a | except KeyError: |
---|
968 | n/a | print('*** end_ifset: KeyError :', len(self.stack) + 1) |
---|
969 | n/a | |
---|
970 | n/a | def bgn_ifclear(self, args): |
---|
971 | n/a | if args in self.values and self.values[args] is not None: |
---|
972 | n/a | self.skip = self.skip + 1 |
---|
973 | n/a | self.stackinfo[len(self.stack)] = 1 |
---|
974 | n/a | else: |
---|
975 | n/a | self.stackinfo[len(self.stack)] = 0 |
---|
976 | n/a | def end_ifclear(self): |
---|
977 | n/a | try: |
---|
978 | n/a | if self.stackinfo[len(self.stack) + 1]: |
---|
979 | n/a | self.skip = self.skip - 1 |
---|
980 | n/a | del self.stackinfo[len(self.stack) + 1] |
---|
981 | n/a | except KeyError: |
---|
982 | n/a | print('*** end_ifclear: KeyError :', len(self.stack) + 1) |
---|
983 | n/a | |
---|
984 | n/a | def open_value(self): |
---|
985 | n/a | self.startsaving() |
---|
986 | n/a | |
---|
987 | n/a | def close_value(self): |
---|
988 | n/a | key = self.collectsavings() |
---|
989 | n/a | if key in self.values: |
---|
990 | n/a | self.write(self.values[key]) |
---|
991 | n/a | else: |
---|
992 | n/a | print('*** Undefined value: ', key) |
---|
993 | n/a | |
---|
994 | n/a | # --- Beginning a file --- |
---|
995 | n/a | |
---|
996 | n/a | do_finalout = do_comment |
---|
997 | n/a | do_setchapternewpage = do_comment |
---|
998 | n/a | do_setfilename = do_comment |
---|
999 | n/a | |
---|
1000 | n/a | def do_settitle(self, args): |
---|
1001 | n/a | self.startsaving() |
---|
1002 | n/a | self.expand(args) |
---|
1003 | n/a | self.title = self.collectsavings() |
---|
1004 | n/a | def do_parskip(self, args): pass |
---|
1005 | n/a | |
---|
1006 | n/a | # --- Ending a file --- |
---|
1007 | n/a | |
---|
1008 | n/a | def do_bye(self, args): |
---|
1009 | n/a | self.endnode() |
---|
1010 | n/a | self.done = 1 |
---|
1011 | n/a | |
---|
1012 | n/a | # --- Title page --- |
---|
1013 | n/a | |
---|
1014 | n/a | def bgn_titlepage(self, args): self.skip = self.skip + 1 |
---|
1015 | n/a | def end_titlepage(self): self.skip = self.skip - 1 |
---|
1016 | n/a | def do_shorttitlepage(self, args): pass |
---|
1017 | n/a | |
---|
1018 | n/a | def do_center(self, args): |
---|
1019 | n/a | # Actually not used outside title page... |
---|
1020 | n/a | self.write('<H1>') |
---|
1021 | n/a | self.expand(args) |
---|
1022 | n/a | self.write('</H1>\n') |
---|
1023 | n/a | do_title = do_center |
---|
1024 | n/a | do_subtitle = do_center |
---|
1025 | n/a | do_author = do_center |
---|
1026 | n/a | |
---|
1027 | n/a | do_vskip = do_comment |
---|
1028 | n/a | do_vfill = do_comment |
---|
1029 | n/a | do_smallbook = do_comment |
---|
1030 | n/a | |
---|
1031 | n/a | do_paragraphindent = do_comment |
---|
1032 | n/a | do_setchapternewpage = do_comment |
---|
1033 | n/a | do_headings = do_comment |
---|
1034 | n/a | do_footnotestyle = do_comment |
---|
1035 | n/a | |
---|
1036 | n/a | do_evenheading = do_comment |
---|
1037 | n/a | do_evenfooting = do_comment |
---|
1038 | n/a | do_oddheading = do_comment |
---|
1039 | n/a | do_oddfooting = do_comment |
---|
1040 | n/a | do_everyheading = do_comment |
---|
1041 | n/a | do_everyfooting = do_comment |
---|
1042 | n/a | |
---|
1043 | n/a | # --- Nodes --- |
---|
1044 | n/a | |
---|
1045 | n/a | def do_node(self, args): |
---|
1046 | n/a | self.endnode() |
---|
1047 | n/a | self.nodelineno = 0 |
---|
1048 | n/a | parts = [s.strip() for s in args.split(',')] |
---|
1049 | n/a | while len(parts) < 4: parts.append('') |
---|
1050 | n/a | self.nodelinks = parts |
---|
1051 | n/a | [name, next, prev, up] = parts[:4] |
---|
1052 | n/a | file = self.dirname + '/' + makefile(name) |
---|
1053 | n/a | if file in self.filenames: |
---|
1054 | n/a | print('*** Filename already in use: ', file) |
---|
1055 | n/a | else: |
---|
1056 | n/a | if self.debugging: print('!'*self.debugging, '--- writing', file) |
---|
1057 | n/a | self.filenames[file] = 1 |
---|
1058 | n/a | # self.nodefp = open(file, 'w') |
---|
1059 | n/a | self.nodename = name |
---|
1060 | n/a | if self.cont and self.nodestack: |
---|
1061 | n/a | self.nodestack[-1].cont = self.nodename |
---|
1062 | n/a | if not self.topname: self.topname = name |
---|
1063 | n/a | title = name |
---|
1064 | n/a | if self.title: title = title + ' -- ' + self.title |
---|
1065 | n/a | self.node = self.Node(self.dirname, self.nodename, self.topname, |
---|
1066 | n/a | title, next, prev, up) |
---|
1067 | n/a | self.htmlhelp.addnode(self.nodename,next,prev,up,file) |
---|
1068 | n/a | |
---|
1069 | n/a | def link(self, label, nodename): |
---|
1070 | n/a | if nodename: |
---|
1071 | n/a | if nodename.lower() == '(dir)': |
---|
1072 | n/a | addr = '../dir.html' |
---|
1073 | n/a | else: |
---|
1074 | n/a | addr = makefile(nodename) |
---|
1075 | n/a | self.write(label, ': <A HREF="', addr, '" TYPE="', |
---|
1076 | n/a | label, '">', nodename, '</A> \n') |
---|
1077 | n/a | |
---|
1078 | n/a | # --- Sectioning commands --- |
---|
1079 | n/a | |
---|
1080 | n/a | def popstack(self, type): |
---|
1081 | n/a | if (self.node): |
---|
1082 | n/a | self.node.type = type |
---|
1083 | n/a | while self.nodestack: |
---|
1084 | n/a | if self.nodestack[-1].type > type: |
---|
1085 | n/a | self.nodestack[-1].finalize() |
---|
1086 | n/a | self.nodestack[-1].flush() |
---|
1087 | n/a | del self.nodestack[-1] |
---|
1088 | n/a | elif self.nodestack[-1].type == type: |
---|
1089 | n/a | if not self.nodestack[-1].next: |
---|
1090 | n/a | self.nodestack[-1].next = self.node.name |
---|
1091 | n/a | if not self.node.prev: |
---|
1092 | n/a | self.node.prev = self.nodestack[-1].name |
---|
1093 | n/a | self.nodestack[-1].finalize() |
---|
1094 | n/a | self.nodestack[-1].flush() |
---|
1095 | n/a | del self.nodestack[-1] |
---|
1096 | n/a | else: |
---|
1097 | n/a | if type > 1 and not self.node.up: |
---|
1098 | n/a | self.node.up = self.nodestack[-1].name |
---|
1099 | n/a | break |
---|
1100 | n/a | |
---|
1101 | n/a | def do_chapter(self, args): |
---|
1102 | n/a | self.heading('H1', args, 0) |
---|
1103 | n/a | self.popstack(1) |
---|
1104 | n/a | |
---|
1105 | n/a | def do_unnumbered(self, args): |
---|
1106 | n/a | self.heading('H1', args, -1) |
---|
1107 | n/a | self.popstack(1) |
---|
1108 | n/a | def do_appendix(self, args): |
---|
1109 | n/a | self.heading('H1', args, -1) |
---|
1110 | n/a | self.popstack(1) |
---|
1111 | n/a | def do_top(self, args): |
---|
1112 | n/a | self.heading('H1', args, -1) |
---|
1113 | n/a | def do_chapheading(self, args): |
---|
1114 | n/a | self.heading('H1', args, -1) |
---|
1115 | n/a | def do_majorheading(self, args): |
---|
1116 | n/a | self.heading('H1', args, -1) |
---|
1117 | n/a | |
---|
1118 | n/a | def do_section(self, args): |
---|
1119 | n/a | self.heading('H1', args, 1) |
---|
1120 | n/a | self.popstack(2) |
---|
1121 | n/a | |
---|
1122 | n/a | def do_unnumberedsec(self, args): |
---|
1123 | n/a | self.heading('H1', args, -1) |
---|
1124 | n/a | self.popstack(2) |
---|
1125 | n/a | def do_appendixsec(self, args): |
---|
1126 | n/a | self.heading('H1', args, -1) |
---|
1127 | n/a | self.popstack(2) |
---|
1128 | n/a | do_appendixsection = do_appendixsec |
---|
1129 | n/a | def do_heading(self, args): |
---|
1130 | n/a | self.heading('H1', args, -1) |
---|
1131 | n/a | |
---|
1132 | n/a | def do_subsection(self, args): |
---|
1133 | n/a | self.heading('H2', args, 2) |
---|
1134 | n/a | self.popstack(3) |
---|
1135 | n/a | def do_unnumberedsubsec(self, args): |
---|
1136 | n/a | self.heading('H2', args, -1) |
---|
1137 | n/a | self.popstack(3) |
---|
1138 | n/a | def do_appendixsubsec(self, args): |
---|
1139 | n/a | self.heading('H2', args, -1) |
---|
1140 | n/a | self.popstack(3) |
---|
1141 | n/a | def do_subheading(self, args): |
---|
1142 | n/a | self.heading('H2', args, -1) |
---|
1143 | n/a | |
---|
1144 | n/a | def do_subsubsection(self, args): |
---|
1145 | n/a | self.heading('H3', args, 3) |
---|
1146 | n/a | self.popstack(4) |
---|
1147 | n/a | def do_unnumberedsubsubsec(self, args): |
---|
1148 | n/a | self.heading('H3', args, -1) |
---|
1149 | n/a | self.popstack(4) |
---|
1150 | n/a | def do_appendixsubsubsec(self, args): |
---|
1151 | n/a | self.heading('H3', args, -1) |
---|
1152 | n/a | self.popstack(4) |
---|
1153 | n/a | def do_subsubheading(self, args): |
---|
1154 | n/a | self.heading('H3', args, -1) |
---|
1155 | n/a | |
---|
1156 | n/a | def heading(self, type, args, level): |
---|
1157 | n/a | if level >= 0: |
---|
1158 | n/a | while len(self.numbering) <= level: |
---|
1159 | n/a | self.numbering.append(0) |
---|
1160 | n/a | del self.numbering[level+1:] |
---|
1161 | n/a | self.numbering[level] = self.numbering[level] + 1 |
---|
1162 | n/a | x = '' |
---|
1163 | n/a | for i in self.numbering: |
---|
1164 | n/a | x = x + repr(i) + '.' |
---|
1165 | n/a | args = x + ' ' + args |
---|
1166 | n/a | self.contents.append((level, args, self.nodename)) |
---|
1167 | n/a | self.write('<', type, '>') |
---|
1168 | n/a | self.expand(args) |
---|
1169 | n/a | self.write('</', type, '>\n') |
---|
1170 | n/a | if self.debugging or self.print_headers: |
---|
1171 | n/a | print('---', args) |
---|
1172 | n/a | |
---|
1173 | n/a | def do_contents(self, args): |
---|
1174 | n/a | # pass |
---|
1175 | n/a | self.listcontents('Table of Contents', 999) |
---|
1176 | n/a | |
---|
1177 | n/a | def do_shortcontents(self, args): |
---|
1178 | n/a | pass |
---|
1179 | n/a | # self.listcontents('Short Contents', 0) |
---|
1180 | n/a | do_summarycontents = do_shortcontents |
---|
1181 | n/a | |
---|
1182 | n/a | def listcontents(self, title, maxlevel): |
---|
1183 | n/a | self.write('<H1>', title, '</H1>\n<UL COMPACT PLAIN>\n') |
---|
1184 | n/a | prevlevels = [0] |
---|
1185 | n/a | for level, title, node in self.contents: |
---|
1186 | n/a | if level > maxlevel: |
---|
1187 | n/a | continue |
---|
1188 | n/a | if level > prevlevels[-1]: |
---|
1189 | n/a | # can only advance one level at a time |
---|
1190 | n/a | self.write(' '*prevlevels[-1], '<UL PLAIN>\n') |
---|
1191 | n/a | prevlevels.append(level) |
---|
1192 | n/a | elif level < prevlevels[-1]: |
---|
1193 | n/a | # might drop back multiple levels |
---|
1194 | n/a | while level < prevlevels[-1]: |
---|
1195 | n/a | del prevlevels[-1] |
---|
1196 | n/a | self.write(' '*prevlevels[-1], |
---|
1197 | n/a | '</UL>\n') |
---|
1198 | n/a | self.write(' '*level, '<LI> <A HREF="', |
---|
1199 | n/a | makefile(node), '">') |
---|
1200 | n/a | self.expand(title) |
---|
1201 | n/a | self.write('</A>\n') |
---|
1202 | n/a | self.write('</UL>\n' * len(prevlevels)) |
---|
1203 | n/a | |
---|
1204 | n/a | # --- Page lay-out --- |
---|
1205 | n/a | |
---|
1206 | n/a | # These commands are only meaningful in printed text |
---|
1207 | n/a | |
---|
1208 | n/a | def do_page(self, args): pass |
---|
1209 | n/a | |
---|
1210 | n/a | def do_need(self, args): pass |
---|
1211 | n/a | |
---|
1212 | n/a | def bgn_group(self, args): pass |
---|
1213 | n/a | def end_group(self): pass |
---|
1214 | n/a | |
---|
1215 | n/a | # --- Line lay-out --- |
---|
1216 | n/a | |
---|
1217 | n/a | def do_sp(self, args): |
---|
1218 | n/a | if self.nofill: |
---|
1219 | n/a | self.write('\n') |
---|
1220 | n/a | else: |
---|
1221 | n/a | self.write('<P>\n') |
---|
1222 | n/a | |
---|
1223 | n/a | def do_hline(self, args): |
---|
1224 | n/a | self.write('<HR>') |
---|
1225 | n/a | |
---|
1226 | n/a | # --- Function and variable definitions --- |
---|
1227 | n/a | |
---|
1228 | n/a | def bgn_deffn(self, args): |
---|
1229 | n/a | self.write('<DL>') |
---|
1230 | n/a | self.do_deffnx(args) |
---|
1231 | n/a | |
---|
1232 | n/a | def end_deffn(self): |
---|
1233 | n/a | self.write('</DL>\n') |
---|
1234 | n/a | |
---|
1235 | n/a | def do_deffnx(self, args): |
---|
1236 | n/a | self.write('<DT>') |
---|
1237 | n/a | words = splitwords(args, 2) |
---|
1238 | n/a | [category, name], rest = words[:2], words[2:] |
---|
1239 | n/a | self.expand('@b{%s}' % name) |
---|
1240 | n/a | for word in rest: self.expand(' ' + makevar(word)) |
---|
1241 | n/a | #self.expand(' -- ' + category) |
---|
1242 | n/a | self.write('\n<DD>') |
---|
1243 | n/a | self.index('fn', name) |
---|
1244 | n/a | |
---|
1245 | n/a | def bgn_defun(self, args): self.bgn_deffn('Function ' + args) |
---|
1246 | n/a | end_defun = end_deffn |
---|
1247 | n/a | def do_defunx(self, args): self.do_deffnx('Function ' + args) |
---|
1248 | n/a | |
---|
1249 | n/a | def bgn_defmac(self, args): self.bgn_deffn('Macro ' + args) |
---|
1250 | n/a | end_defmac = end_deffn |
---|
1251 | n/a | def do_defmacx(self, args): self.do_deffnx('Macro ' + args) |
---|
1252 | n/a | |
---|
1253 | n/a | def bgn_defspec(self, args): self.bgn_deffn('{Special Form} ' + args) |
---|
1254 | n/a | end_defspec = end_deffn |
---|
1255 | n/a | def do_defspecx(self, args): self.do_deffnx('{Special Form} ' + args) |
---|
1256 | n/a | |
---|
1257 | n/a | def bgn_defvr(self, args): |
---|
1258 | n/a | self.write('<DL>') |
---|
1259 | n/a | self.do_defvrx(args) |
---|
1260 | n/a | |
---|
1261 | n/a | end_defvr = end_deffn |
---|
1262 | n/a | |
---|
1263 | n/a | def do_defvrx(self, args): |
---|
1264 | n/a | self.write('<DT>') |
---|
1265 | n/a | words = splitwords(args, 2) |
---|
1266 | n/a | [category, name], rest = words[:2], words[2:] |
---|
1267 | n/a | self.expand('@code{%s}' % name) |
---|
1268 | n/a | # If there are too many arguments, show them |
---|
1269 | n/a | for word in rest: self.expand(' ' + word) |
---|
1270 | n/a | #self.expand(' -- ' + category) |
---|
1271 | n/a | self.write('\n<DD>') |
---|
1272 | n/a | self.index('vr', name) |
---|
1273 | n/a | |
---|
1274 | n/a | def bgn_defvar(self, args): self.bgn_defvr('Variable ' + args) |
---|
1275 | n/a | end_defvar = end_defvr |
---|
1276 | n/a | def do_defvarx(self, args): self.do_defvrx('Variable ' + args) |
---|
1277 | n/a | |
---|
1278 | n/a | def bgn_defopt(self, args): self.bgn_defvr('{User Option} ' + args) |
---|
1279 | n/a | end_defopt = end_defvr |
---|
1280 | n/a | def do_defoptx(self, args): self.do_defvrx('{User Option} ' + args) |
---|
1281 | n/a | |
---|
1282 | n/a | # --- Ditto for typed languages --- |
---|
1283 | n/a | |
---|
1284 | n/a | def bgn_deftypefn(self, args): |
---|
1285 | n/a | self.write('<DL>') |
---|
1286 | n/a | self.do_deftypefnx(args) |
---|
1287 | n/a | |
---|
1288 | n/a | end_deftypefn = end_deffn |
---|
1289 | n/a | |
---|
1290 | n/a | def do_deftypefnx(self, args): |
---|
1291 | n/a | self.write('<DT>') |
---|
1292 | n/a | words = splitwords(args, 3) |
---|
1293 | n/a | [category, datatype, name], rest = words[:3], words[3:] |
---|
1294 | n/a | self.expand('@code{%s} @b{%s}' % (datatype, name)) |
---|
1295 | n/a | for word in rest: self.expand(' ' + makevar(word)) |
---|
1296 | n/a | #self.expand(' -- ' + category) |
---|
1297 | n/a | self.write('\n<DD>') |
---|
1298 | n/a | self.index('fn', name) |
---|
1299 | n/a | |
---|
1300 | n/a | |
---|
1301 | n/a | def bgn_deftypefun(self, args): self.bgn_deftypefn('Function ' + args) |
---|
1302 | n/a | end_deftypefun = end_deftypefn |
---|
1303 | n/a | def do_deftypefunx(self, args): self.do_deftypefnx('Function ' + args) |
---|
1304 | n/a | |
---|
1305 | n/a | def bgn_deftypevr(self, args): |
---|
1306 | n/a | self.write('<DL>') |
---|
1307 | n/a | self.do_deftypevrx(args) |
---|
1308 | n/a | |
---|
1309 | n/a | end_deftypevr = end_deftypefn |
---|
1310 | n/a | |
---|
1311 | n/a | def do_deftypevrx(self, args): |
---|
1312 | n/a | self.write('<DT>') |
---|
1313 | n/a | words = splitwords(args, 3) |
---|
1314 | n/a | [category, datatype, name], rest = words[:3], words[3:] |
---|
1315 | n/a | self.expand('@code{%s} @b{%s}' % (datatype, name)) |
---|
1316 | n/a | # If there are too many arguments, show them |
---|
1317 | n/a | for word in rest: self.expand(' ' + word) |
---|
1318 | n/a | #self.expand(' -- ' + category) |
---|
1319 | n/a | self.write('\n<DD>') |
---|
1320 | n/a | self.index('fn', name) |
---|
1321 | n/a | |
---|
1322 | n/a | def bgn_deftypevar(self, args): |
---|
1323 | n/a | self.bgn_deftypevr('Variable ' + args) |
---|
1324 | n/a | end_deftypevar = end_deftypevr |
---|
1325 | n/a | def do_deftypevarx(self, args): |
---|
1326 | n/a | self.do_deftypevrx('Variable ' + args) |
---|
1327 | n/a | |
---|
1328 | n/a | # --- Ditto for object-oriented languages --- |
---|
1329 | n/a | |
---|
1330 | n/a | def bgn_defcv(self, args): |
---|
1331 | n/a | self.write('<DL>') |
---|
1332 | n/a | self.do_defcvx(args) |
---|
1333 | n/a | |
---|
1334 | n/a | end_defcv = end_deftypevr |
---|
1335 | n/a | |
---|
1336 | n/a | def do_defcvx(self, args): |
---|
1337 | n/a | self.write('<DT>') |
---|
1338 | n/a | words = splitwords(args, 3) |
---|
1339 | n/a | [category, classname, name], rest = words[:3], words[3:] |
---|
1340 | n/a | self.expand('@b{%s}' % name) |
---|
1341 | n/a | # If there are too many arguments, show them |
---|
1342 | n/a | for word in rest: self.expand(' ' + word) |
---|
1343 | n/a | #self.expand(' -- %s of @code{%s}' % (category, classname)) |
---|
1344 | n/a | self.write('\n<DD>') |
---|
1345 | n/a | self.index('vr', '%s @r{on %s}' % (name, classname)) |
---|
1346 | n/a | |
---|
1347 | n/a | def bgn_defivar(self, args): |
---|
1348 | n/a | self.bgn_defcv('{Instance Variable} ' + args) |
---|
1349 | n/a | end_defivar = end_defcv |
---|
1350 | n/a | def do_defivarx(self, args): |
---|
1351 | n/a | self.do_defcvx('{Instance Variable} ' + args) |
---|
1352 | n/a | |
---|
1353 | n/a | def bgn_defop(self, args): |
---|
1354 | n/a | self.write('<DL>') |
---|
1355 | n/a | self.do_defopx(args) |
---|
1356 | n/a | |
---|
1357 | n/a | end_defop = end_defcv |
---|
1358 | n/a | |
---|
1359 | n/a | def do_defopx(self, args): |
---|
1360 | n/a | self.write('<DT>') |
---|
1361 | n/a | words = splitwords(args, 3) |
---|
1362 | n/a | [category, classname, name], rest = words[:3], words[3:] |
---|
1363 | n/a | self.expand('@b{%s}' % name) |
---|
1364 | n/a | for word in rest: self.expand(' ' + makevar(word)) |
---|
1365 | n/a | #self.expand(' -- %s of @code{%s}' % (category, classname)) |
---|
1366 | n/a | self.write('\n<DD>') |
---|
1367 | n/a | self.index('fn', '%s @r{on %s}' % (name, classname)) |
---|
1368 | n/a | |
---|
1369 | n/a | def bgn_defmethod(self, args): |
---|
1370 | n/a | self.bgn_defop('Method ' + args) |
---|
1371 | n/a | end_defmethod = end_defop |
---|
1372 | n/a | def do_defmethodx(self, args): |
---|
1373 | n/a | self.do_defopx('Method ' + args) |
---|
1374 | n/a | |
---|
1375 | n/a | # --- Ditto for data types --- |
---|
1376 | n/a | |
---|
1377 | n/a | def bgn_deftp(self, args): |
---|
1378 | n/a | self.write('<DL>') |
---|
1379 | n/a | self.do_deftpx(args) |
---|
1380 | n/a | |
---|
1381 | n/a | end_deftp = end_defcv |
---|
1382 | n/a | |
---|
1383 | n/a | def do_deftpx(self, args): |
---|
1384 | n/a | self.write('<DT>') |
---|
1385 | n/a | words = splitwords(args, 2) |
---|
1386 | n/a | [category, name], rest = words[:2], words[2:] |
---|
1387 | n/a | self.expand('@b{%s}' % name) |
---|
1388 | n/a | for word in rest: self.expand(' ' + word) |
---|
1389 | n/a | #self.expand(' -- ' + category) |
---|
1390 | n/a | self.write('\n<DD>') |
---|
1391 | n/a | self.index('tp', name) |
---|
1392 | n/a | |
---|
1393 | n/a | # --- Making Lists and Tables |
---|
1394 | n/a | |
---|
1395 | n/a | def bgn_enumerate(self, args): |
---|
1396 | n/a | if not args: |
---|
1397 | n/a | self.write('<OL>\n') |
---|
1398 | n/a | self.stackinfo[len(self.stack)] = '</OL>\n' |
---|
1399 | n/a | else: |
---|
1400 | n/a | self.itemnumber = args |
---|
1401 | n/a | self.write('<UL>\n') |
---|
1402 | n/a | self.stackinfo[len(self.stack)] = '</UL>\n' |
---|
1403 | n/a | def end_enumerate(self): |
---|
1404 | n/a | self.itemnumber = None |
---|
1405 | n/a | self.write(self.stackinfo[len(self.stack) + 1]) |
---|
1406 | n/a | del self.stackinfo[len(self.stack) + 1] |
---|
1407 | n/a | |
---|
1408 | n/a | def bgn_itemize(self, args): |
---|
1409 | n/a | self.itemarg = args |
---|
1410 | n/a | self.write('<UL>\n') |
---|
1411 | n/a | def end_itemize(self): |
---|
1412 | n/a | self.itemarg = None |
---|
1413 | n/a | self.write('</UL>\n') |
---|
1414 | n/a | |
---|
1415 | n/a | def bgn_table(self, args): |
---|
1416 | n/a | self.itemarg = args |
---|
1417 | n/a | self.write('<DL>\n') |
---|
1418 | n/a | def end_table(self): |
---|
1419 | n/a | self.itemarg = None |
---|
1420 | n/a | self.write('</DL>\n') |
---|
1421 | n/a | |
---|
1422 | n/a | def bgn_ftable(self, args): |
---|
1423 | n/a | self.itemindex = 'fn' |
---|
1424 | n/a | self.bgn_table(args) |
---|
1425 | n/a | def end_ftable(self): |
---|
1426 | n/a | self.itemindex = None |
---|
1427 | n/a | self.end_table() |
---|
1428 | n/a | |
---|
1429 | n/a | def bgn_vtable(self, args): |
---|
1430 | n/a | self.itemindex = 'vr' |
---|
1431 | n/a | self.bgn_table(args) |
---|
1432 | n/a | def end_vtable(self): |
---|
1433 | n/a | self.itemindex = None |
---|
1434 | n/a | self.end_table() |
---|
1435 | n/a | |
---|
1436 | n/a | def do_item(self, args): |
---|
1437 | n/a | if self.itemindex: self.index(self.itemindex, args) |
---|
1438 | n/a | if self.itemarg: |
---|
1439 | n/a | if self.itemarg[0] == '@' and self.itemarg[1] and \ |
---|
1440 | n/a | self.itemarg[1] in string.ascii_letters: |
---|
1441 | n/a | args = self.itemarg + '{' + args + '}' |
---|
1442 | n/a | else: |
---|
1443 | n/a | # some other character, e.g. '-' |
---|
1444 | n/a | args = self.itemarg + ' ' + args |
---|
1445 | n/a | if self.itemnumber is not None: |
---|
1446 | n/a | args = self.itemnumber + '. ' + args |
---|
1447 | n/a | self.itemnumber = increment(self.itemnumber) |
---|
1448 | n/a | if self.stack and self.stack[-1] == 'table': |
---|
1449 | n/a | self.write('<DT>') |
---|
1450 | n/a | self.expand(args) |
---|
1451 | n/a | self.write('\n<DD>') |
---|
1452 | n/a | elif self.stack and self.stack[-1] == 'multitable': |
---|
1453 | n/a | self.write('<TR><TD>') |
---|
1454 | n/a | self.expand(args) |
---|
1455 | n/a | self.write('</TD>\n</TR>\n') |
---|
1456 | n/a | else: |
---|
1457 | n/a | self.write('<LI>') |
---|
1458 | n/a | self.expand(args) |
---|
1459 | n/a | self.write(' ') |
---|
1460 | n/a | do_itemx = do_item # XXX Should suppress leading blank line |
---|
1461 | n/a | |
---|
1462 | n/a | # rpyron 2002-05-07 multitable support |
---|
1463 | n/a | def bgn_multitable(self, args): |
---|
1464 | n/a | self.itemarg = None # should be handled by columnfractions |
---|
1465 | n/a | self.write('<TABLE BORDER="">\n') |
---|
1466 | n/a | def end_multitable(self): |
---|
1467 | n/a | self.itemarg = None |
---|
1468 | n/a | self.write('</TABLE>\n<BR>\n') |
---|
1469 | n/a | def handle_columnfractions(self): |
---|
1470 | n/a | # It would be better to handle this, but for now it's in the way... |
---|
1471 | n/a | self.itemarg = None |
---|
1472 | n/a | def handle_tab(self): |
---|
1473 | n/a | self.write('</TD>\n <TD>') |
---|
1474 | n/a | |
---|
1475 | n/a | # --- Enumerations, displays, quotations --- |
---|
1476 | n/a | # XXX Most of these should increase the indentation somehow |
---|
1477 | n/a | |
---|
1478 | n/a | def bgn_quotation(self, args): self.write('<BLOCKQUOTE>') |
---|
1479 | n/a | def end_quotation(self): self.write('</BLOCKQUOTE>\n') |
---|
1480 | n/a | |
---|
1481 | n/a | def bgn_example(self, args): |
---|
1482 | n/a | self.nofill = self.nofill + 1 |
---|
1483 | n/a | self.write('<PRE>') |
---|
1484 | n/a | def end_example(self): |
---|
1485 | n/a | self.write('</PRE>\n') |
---|
1486 | n/a | self.nofill = self.nofill - 1 |
---|
1487 | n/a | |
---|
1488 | n/a | bgn_lisp = bgn_example # Synonym when contents are executable lisp code |
---|
1489 | n/a | end_lisp = end_example |
---|
1490 | n/a | |
---|
1491 | n/a | bgn_smallexample = bgn_example # XXX Should use smaller font |
---|
1492 | n/a | end_smallexample = end_example |
---|
1493 | n/a | |
---|
1494 | n/a | bgn_smalllisp = bgn_lisp # Ditto |
---|
1495 | n/a | end_smalllisp = end_lisp |
---|
1496 | n/a | |
---|
1497 | n/a | bgn_display = bgn_example |
---|
1498 | n/a | end_display = end_example |
---|
1499 | n/a | |
---|
1500 | n/a | bgn_format = bgn_display |
---|
1501 | n/a | end_format = end_display |
---|
1502 | n/a | |
---|
1503 | n/a | def do_exdent(self, args): self.expand(args + '\n') |
---|
1504 | n/a | # XXX Should really mess with indentation |
---|
1505 | n/a | |
---|
1506 | n/a | def bgn_flushleft(self, args): |
---|
1507 | n/a | self.nofill = self.nofill + 1 |
---|
1508 | n/a | self.write('<PRE>\n') |
---|
1509 | n/a | def end_flushleft(self): |
---|
1510 | n/a | self.write('</PRE>\n') |
---|
1511 | n/a | self.nofill = self.nofill - 1 |
---|
1512 | n/a | |
---|
1513 | n/a | def bgn_flushright(self, args): |
---|
1514 | n/a | self.nofill = self.nofill + 1 |
---|
1515 | n/a | self.write('<ADDRESS COMPACT>\n') |
---|
1516 | n/a | def end_flushright(self): |
---|
1517 | n/a | self.write('</ADDRESS>\n') |
---|
1518 | n/a | self.nofill = self.nofill - 1 |
---|
1519 | n/a | |
---|
1520 | n/a | def bgn_menu(self, args): |
---|
1521 | n/a | self.write('<DIR>\n') |
---|
1522 | n/a | self.write(' <STRONG><EM>Menu</EM></STRONG><P>\n') |
---|
1523 | n/a | self.htmlhelp.beginmenu() |
---|
1524 | n/a | def end_menu(self): |
---|
1525 | n/a | self.write('</DIR>\n') |
---|
1526 | n/a | self.htmlhelp.endmenu() |
---|
1527 | n/a | |
---|
1528 | n/a | def bgn_cartouche(self, args): pass |
---|
1529 | n/a | def end_cartouche(self): pass |
---|
1530 | n/a | |
---|
1531 | n/a | # --- Indices --- |
---|
1532 | n/a | |
---|
1533 | n/a | def resetindex(self): |
---|
1534 | n/a | self.noncodeindices = ['cp'] |
---|
1535 | n/a | self.indextitle = {} |
---|
1536 | n/a | self.indextitle['cp'] = 'Concept' |
---|
1537 | n/a | self.indextitle['fn'] = 'Function' |
---|
1538 | n/a | self.indextitle['ky'] = 'Keyword' |
---|
1539 | n/a | self.indextitle['pg'] = 'Program' |
---|
1540 | n/a | self.indextitle['tp'] = 'Type' |
---|
1541 | n/a | self.indextitle['vr'] = 'Variable' |
---|
1542 | n/a | # |
---|
1543 | n/a | self.whichindex = {} |
---|
1544 | n/a | for name in self.indextitle: |
---|
1545 | n/a | self.whichindex[name] = [] |
---|
1546 | n/a | |
---|
1547 | n/a | def user_index(self, name, args): |
---|
1548 | n/a | if name in self.whichindex: |
---|
1549 | n/a | self.index(name, args) |
---|
1550 | n/a | else: |
---|
1551 | n/a | print('*** No index named', repr(name)) |
---|
1552 | n/a | |
---|
1553 | n/a | def do_cindex(self, args): self.index('cp', args) |
---|
1554 | n/a | def do_findex(self, args): self.index('fn', args) |
---|
1555 | n/a | def do_kindex(self, args): self.index('ky', args) |
---|
1556 | n/a | def do_pindex(self, args): self.index('pg', args) |
---|
1557 | n/a | def do_tindex(self, args): self.index('tp', args) |
---|
1558 | n/a | def do_vindex(self, args): self.index('vr', args) |
---|
1559 | n/a | |
---|
1560 | n/a | def index(self, name, args): |
---|
1561 | n/a | self.whichindex[name].append((args, self.nodename)) |
---|
1562 | n/a | self.htmlhelp.index(args, self.nodename) |
---|
1563 | n/a | |
---|
1564 | n/a | def do_synindex(self, args): |
---|
1565 | n/a | words = args.split() |
---|
1566 | n/a | if len(words) != 2: |
---|
1567 | n/a | print('*** bad @synindex', args) |
---|
1568 | n/a | return |
---|
1569 | n/a | [old, new] = words |
---|
1570 | n/a | if old not in self.whichindex or \ |
---|
1571 | n/a | new not in self.whichindex: |
---|
1572 | n/a | print('*** bad key(s) in @synindex', args) |
---|
1573 | n/a | return |
---|
1574 | n/a | if old != new and \ |
---|
1575 | n/a | self.whichindex[old] is not self.whichindex[new]: |
---|
1576 | n/a | inew = self.whichindex[new] |
---|
1577 | n/a | inew[len(inew):] = self.whichindex[old] |
---|
1578 | n/a | self.whichindex[old] = inew |
---|
1579 | n/a | do_syncodeindex = do_synindex # XXX Should use code font |
---|
1580 | n/a | |
---|
1581 | n/a | def do_printindex(self, args): |
---|
1582 | n/a | words = args.split() |
---|
1583 | n/a | for name in words: |
---|
1584 | n/a | if name in self.whichindex: |
---|
1585 | n/a | self.prindex(name) |
---|
1586 | n/a | else: |
---|
1587 | n/a | print('*** No index named', repr(name)) |
---|
1588 | n/a | |
---|
1589 | n/a | def prindex(self, name): |
---|
1590 | n/a | iscodeindex = (name not in self.noncodeindices) |
---|
1591 | n/a | index = self.whichindex[name] |
---|
1592 | n/a | if not index: return |
---|
1593 | n/a | if self.debugging: |
---|
1594 | n/a | print('!'*self.debugging, '--- Generating', \ |
---|
1595 | n/a | self.indextitle[name], 'index') |
---|
1596 | n/a | # The node already provides a title |
---|
1597 | n/a | index1 = [] |
---|
1598 | n/a | junkprog = re.compile('^(@[a-z]+)?{') |
---|
1599 | n/a | for key, node in index: |
---|
1600 | n/a | sortkey = key.lower() |
---|
1601 | n/a | # Remove leading `@cmd{' from sort key |
---|
1602 | n/a | # -- don't bother about the matching `}' |
---|
1603 | n/a | oldsortkey = sortkey |
---|
1604 | n/a | while 1: |
---|
1605 | n/a | mo = junkprog.match(sortkey) |
---|
1606 | n/a | if not mo: |
---|
1607 | n/a | break |
---|
1608 | n/a | i = mo.end() |
---|
1609 | n/a | sortkey = sortkey[i:] |
---|
1610 | n/a | index1.append((sortkey, key, node)) |
---|
1611 | n/a | del index[:] |
---|
1612 | n/a | index1.sort() |
---|
1613 | n/a | self.write('<DL COMPACT>\n') |
---|
1614 | n/a | prevkey = prevnode = None |
---|
1615 | n/a | for sortkey, key, node in index1: |
---|
1616 | n/a | if (key, node) == (prevkey, prevnode): |
---|
1617 | n/a | continue |
---|
1618 | n/a | if self.debugging > 1: print('!'*self.debugging, key, ':', node) |
---|
1619 | n/a | self.write('<DT>') |
---|
1620 | n/a | if iscodeindex: key = '@code{' + key + '}' |
---|
1621 | n/a | if key != prevkey: |
---|
1622 | n/a | self.expand(key) |
---|
1623 | n/a | self.write('\n<DD><A HREF="%s">%s</A>\n' % (makefile(node), node)) |
---|
1624 | n/a | prevkey, prevnode = key, node |
---|
1625 | n/a | self.write('</DL>\n') |
---|
1626 | n/a | |
---|
1627 | n/a | # --- Final error reports --- |
---|
1628 | n/a | |
---|
1629 | n/a | def report(self): |
---|
1630 | n/a | if self.unknown: |
---|
1631 | n/a | print('--- Unrecognized commands ---') |
---|
1632 | n/a | cmds = sorted(self.unknown.keys()) |
---|
1633 | n/a | for cmd in cmds: |
---|
1634 | n/a | print(cmd.ljust(20), self.unknown[cmd]) |
---|
1635 | n/a | |
---|
1636 | n/a | |
---|
1637 | n/a | class TexinfoParserHTML3(TexinfoParser): |
---|
1638 | n/a | |
---|
1639 | n/a | COPYRIGHT_SYMBOL = "©" |
---|
1640 | n/a | FN_ID_PATTERN = "[%(id)s]" |
---|
1641 | n/a | FN_SOURCE_PATTERN = '<A ID=footnoteref%(id)s ' \ |
---|
1642 | n/a | 'HREF="#footnotetext%(id)s">' + FN_ID_PATTERN + '</A>' |
---|
1643 | n/a | FN_TARGET_PATTERN = '<FN ID=footnotetext%(id)s>\n' \ |
---|
1644 | n/a | '<P><A HREF="#footnoteref%(id)s">' + FN_ID_PATTERN \ |
---|
1645 | n/a | + '</A>\n%(text)s</P></FN>\n' |
---|
1646 | n/a | FN_HEADER = '<DIV CLASS=footnotes>\n <HR NOSHADE WIDTH=200>\n' \ |
---|
1647 | n/a | ' <STRONG><EM>Footnotes</EM></STRONG>\n <P>\n' |
---|
1648 | n/a | |
---|
1649 | n/a | Node = HTML3Node |
---|
1650 | n/a | |
---|
1651 | n/a | def bgn_quotation(self, args): self.write('<BQ>') |
---|
1652 | n/a | def end_quotation(self): self.write('</BQ>\n') |
---|
1653 | n/a | |
---|
1654 | n/a | def bgn_example(self, args): |
---|
1655 | n/a | # this use of <CODE> would not be legal in HTML 2.0, |
---|
1656 | n/a | # but is in more recent DTDs. |
---|
1657 | n/a | self.nofill = self.nofill + 1 |
---|
1658 | n/a | self.write('<PRE CLASS=example><CODE>') |
---|
1659 | n/a | def end_example(self): |
---|
1660 | n/a | self.write("</CODE></PRE>\n") |
---|
1661 | n/a | self.nofill = self.nofill - 1 |
---|
1662 | n/a | |
---|
1663 | n/a | def bgn_flushleft(self, args): |
---|
1664 | n/a | self.nofill = self.nofill + 1 |
---|
1665 | n/a | self.write('<PRE CLASS=flushleft>\n') |
---|
1666 | n/a | |
---|
1667 | n/a | def bgn_flushright(self, args): |
---|
1668 | n/a | self.nofill = self.nofill + 1 |
---|
1669 | n/a | self.write('<DIV ALIGN=right CLASS=flushright><ADDRESS COMPACT>\n') |
---|
1670 | n/a | def end_flushright(self): |
---|
1671 | n/a | self.write('</ADDRESS></DIV>\n') |
---|
1672 | n/a | self.nofill = self.nofill - 1 |
---|
1673 | n/a | |
---|
1674 | n/a | def bgn_menu(self, args): |
---|
1675 | n/a | self.write('<UL PLAIN CLASS=menu>\n') |
---|
1676 | n/a | self.write(' <LH>Menu</LH>\n') |
---|
1677 | n/a | def end_menu(self): |
---|
1678 | n/a | self.write('</UL>\n') |
---|
1679 | n/a | |
---|
1680 | n/a | |
---|
1681 | n/a | # rpyron 2002-05-07 |
---|
1682 | n/a | class HTMLHelp: |
---|
1683 | n/a | """ |
---|
1684 | n/a | This class encapsulates support for HTML Help. Node names, |
---|
1685 | n/a | file names, menu items, index items, and image file names are |
---|
1686 | n/a | accumulated until a call to finalize(). At that time, three |
---|
1687 | n/a | output files are created in the current directory: |
---|
1688 | n/a | |
---|
1689 | n/a | `helpbase`.hhp is a HTML Help Workshop project file. |
---|
1690 | n/a | It contains various information, some of |
---|
1691 | n/a | which I do not understand; I just copied |
---|
1692 | n/a | the default project info from a fresh |
---|
1693 | n/a | installation. |
---|
1694 | n/a | `helpbase`.hhc is the Contents file for the project. |
---|
1695 | n/a | `helpbase`.hhk is the Index file for the project. |
---|
1696 | n/a | |
---|
1697 | n/a | When these files are used as input to HTML Help Workshop, |
---|
1698 | n/a | the resulting file will be named: |
---|
1699 | n/a | |
---|
1700 | n/a | `helpbase`.chm |
---|
1701 | n/a | |
---|
1702 | n/a | If none of the defaults in `helpbase`.hhp are changed, |
---|
1703 | n/a | the .CHM file will have Contents, Index, Search, and |
---|
1704 | n/a | Favorites tabs. |
---|
1705 | n/a | """ |
---|
1706 | n/a | |
---|
1707 | n/a | codeprog = re.compile('@code{(.*?)}') |
---|
1708 | n/a | |
---|
1709 | n/a | def __init__(self,helpbase,dirname): |
---|
1710 | n/a | self.helpbase = helpbase |
---|
1711 | n/a | self.dirname = dirname |
---|
1712 | n/a | self.projectfile = None |
---|
1713 | n/a | self.contentfile = None |
---|
1714 | n/a | self.indexfile = None |
---|
1715 | n/a | self.nodelist = [] |
---|
1716 | n/a | self.nodenames = {} # nodename : index |
---|
1717 | n/a | self.nodeindex = {} |
---|
1718 | n/a | self.filenames = {} # filename : filename |
---|
1719 | n/a | self.indexlist = [] # (args,nodename) == (key,location) |
---|
1720 | n/a | self.current = '' |
---|
1721 | n/a | self.menudict = {} |
---|
1722 | n/a | self.dumped = {} |
---|
1723 | n/a | |
---|
1724 | n/a | |
---|
1725 | n/a | def addnode(self,name,next,prev,up,filename): |
---|
1726 | n/a | node = (name,next,prev,up,filename) |
---|
1727 | n/a | # add this file to dict |
---|
1728 | n/a | # retrieve list with self.filenames.values() |
---|
1729 | n/a | self.filenames[filename] = filename |
---|
1730 | n/a | # add this node to nodelist |
---|
1731 | n/a | self.nodeindex[name] = len(self.nodelist) |
---|
1732 | n/a | self.nodelist.append(node) |
---|
1733 | n/a | # set 'current' for menu items |
---|
1734 | n/a | self.current = name |
---|
1735 | n/a | self.menudict[self.current] = [] |
---|
1736 | n/a | |
---|
1737 | n/a | def menuitem(self,nodename): |
---|
1738 | n/a | menu = self.menudict[self.current] |
---|
1739 | n/a | menu.append(nodename) |
---|
1740 | n/a | |
---|
1741 | n/a | |
---|
1742 | n/a | def addimage(self,imagename): |
---|
1743 | n/a | self.filenames[imagename] = imagename |
---|
1744 | n/a | |
---|
1745 | n/a | def index(self, args, nodename): |
---|
1746 | n/a | self.indexlist.append((args,nodename)) |
---|
1747 | n/a | |
---|
1748 | n/a | def beginmenu(self): |
---|
1749 | n/a | pass |
---|
1750 | n/a | |
---|
1751 | n/a | def endmenu(self): |
---|
1752 | n/a | pass |
---|
1753 | n/a | |
---|
1754 | n/a | def finalize(self): |
---|
1755 | n/a | if not self.helpbase: |
---|
1756 | n/a | return |
---|
1757 | n/a | |
---|
1758 | n/a | # generate interesting filenames |
---|
1759 | n/a | resultfile = self.helpbase + '.chm' |
---|
1760 | n/a | projectfile = self.helpbase + '.hhp' |
---|
1761 | n/a | contentfile = self.helpbase + '.hhc' |
---|
1762 | n/a | indexfile = self.helpbase + '.hhk' |
---|
1763 | n/a | |
---|
1764 | n/a | # generate a reasonable title |
---|
1765 | n/a | title = self.helpbase |
---|
1766 | n/a | |
---|
1767 | n/a | # get the default topic file |
---|
1768 | n/a | (topname,topnext,topprev,topup,topfile) = self.nodelist[0] |
---|
1769 | n/a | defaulttopic = topfile |
---|
1770 | n/a | |
---|
1771 | n/a | # PROJECT FILE |
---|
1772 | n/a | try: |
---|
1773 | n/a | fp = open(projectfile,'w') |
---|
1774 | n/a | print('[OPTIONS]', file=fp) |
---|
1775 | n/a | print('Auto Index=Yes', file=fp) |
---|
1776 | n/a | print('Binary TOC=No', file=fp) |
---|
1777 | n/a | print('Binary Index=Yes', file=fp) |
---|
1778 | n/a | print('Compatibility=1.1', file=fp) |
---|
1779 | n/a | print('Compiled file=' + resultfile + '', file=fp) |
---|
1780 | n/a | print('Contents file=' + contentfile + '', file=fp) |
---|
1781 | n/a | print('Default topic=' + defaulttopic + '', file=fp) |
---|
1782 | n/a | print('Error log file=ErrorLog.log', file=fp) |
---|
1783 | n/a | print('Index file=' + indexfile + '', file=fp) |
---|
1784 | n/a | print('Title=' + title + '', file=fp) |
---|
1785 | n/a | print('Display compile progress=Yes', file=fp) |
---|
1786 | n/a | print('Full-text search=Yes', file=fp) |
---|
1787 | n/a | print('Default window=main', file=fp) |
---|
1788 | n/a | print('', file=fp) |
---|
1789 | n/a | print('[WINDOWS]', file=fp) |
---|
1790 | n/a | print('main=,"' + contentfile + '","' + indexfile |
---|
1791 | n/a | + '","","",,,,,0x23520,222,0x1046,[10,10,780,560],' |
---|
1792 | n/a | '0xB0000,,,,,,0', file=fp) |
---|
1793 | n/a | print('', file=fp) |
---|
1794 | n/a | print('[FILES]', file=fp) |
---|
1795 | n/a | print('', file=fp) |
---|
1796 | n/a | self.dumpfiles(fp) |
---|
1797 | n/a | fp.close() |
---|
1798 | n/a | except IOError as msg: |
---|
1799 | n/a | print(projectfile, ':', msg) |
---|
1800 | n/a | sys.exit(1) |
---|
1801 | n/a | |
---|
1802 | n/a | # CONTENT FILE |
---|
1803 | n/a | try: |
---|
1804 | n/a | fp = open(contentfile,'w') |
---|
1805 | n/a | print('<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">', file=fp) |
---|
1806 | n/a | print('<!-- This file defines the table of contents -->', file=fp) |
---|
1807 | n/a | print('<HTML>', file=fp) |
---|
1808 | n/a | print('<HEAD>', file=fp) |
---|
1809 | n/a | print('<meta name="GENERATOR"' |
---|
1810 | n/a | 'content="Microsoft® HTML Help Workshop 4.1">', file=fp) |
---|
1811 | n/a | print('<!-- Sitemap 1.0 -->', file=fp) |
---|
1812 | n/a | print('</HEAD>', file=fp) |
---|
1813 | n/a | print('<BODY>', file=fp) |
---|
1814 | n/a | print(' <OBJECT type="text/site properties">', file=fp) |
---|
1815 | n/a | print(' <param name="Window Styles" value="0x800025">', file=fp) |
---|
1816 | n/a | print(' <param name="comment" value="title:">', file=fp) |
---|
1817 | n/a | print(' <param name="comment" value="base:">', file=fp) |
---|
1818 | n/a | print(' </OBJECT>', file=fp) |
---|
1819 | n/a | self.dumpnodes(fp) |
---|
1820 | n/a | print('</BODY>', file=fp) |
---|
1821 | n/a | print('</HTML>', file=fp) |
---|
1822 | n/a | fp.close() |
---|
1823 | n/a | except IOError as msg: |
---|
1824 | n/a | print(contentfile, ':', msg) |
---|
1825 | n/a | sys.exit(1) |
---|
1826 | n/a | |
---|
1827 | n/a | # INDEX FILE |
---|
1828 | n/a | try: |
---|
1829 | n/a | fp = open(indexfile ,'w') |
---|
1830 | n/a | print('<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">', file=fp) |
---|
1831 | n/a | print('<!-- This file defines the index -->', file=fp) |
---|
1832 | n/a | print('<HTML>', file=fp) |
---|
1833 | n/a | print('<HEAD>', file=fp) |
---|
1834 | n/a | print('<meta name="GENERATOR"' |
---|
1835 | n/a | 'content="Microsoft® HTML Help Workshop 4.1">', file=fp) |
---|
1836 | n/a | print('<!-- Sitemap 1.0 -->', file=fp) |
---|
1837 | n/a | print('</HEAD>', file=fp) |
---|
1838 | n/a | print('<BODY>', file=fp) |
---|
1839 | n/a | print('<OBJECT type="text/site properties">', file=fp) |
---|
1840 | n/a | print('</OBJECT>', file=fp) |
---|
1841 | n/a | self.dumpindex(fp) |
---|
1842 | n/a | print('</BODY>', file=fp) |
---|
1843 | n/a | print('</HTML>', file=fp) |
---|
1844 | n/a | fp.close() |
---|
1845 | n/a | except IOError as msg: |
---|
1846 | n/a | print(indexfile , ':', msg) |
---|
1847 | n/a | sys.exit(1) |
---|
1848 | n/a | |
---|
1849 | n/a | def dumpfiles(self, outfile=sys.stdout): |
---|
1850 | n/a | filelist = sorted(self.filenames.values()) |
---|
1851 | n/a | for filename in filelist: |
---|
1852 | n/a | print(filename, file=outfile) |
---|
1853 | n/a | |
---|
1854 | n/a | def dumpnodes(self, outfile=sys.stdout): |
---|
1855 | n/a | self.dumped = {} |
---|
1856 | n/a | if self.nodelist: |
---|
1857 | n/a | nodename, dummy, dummy, dummy, dummy = self.nodelist[0] |
---|
1858 | n/a | self.topnode = nodename |
---|
1859 | n/a | |
---|
1860 | n/a | print('<UL>', file=outfile) |
---|
1861 | n/a | for node in self.nodelist: |
---|
1862 | n/a | self.dumpnode(node,0,outfile) |
---|
1863 | n/a | print('</UL>', file=outfile) |
---|
1864 | n/a | |
---|
1865 | n/a | def dumpnode(self, node, indent=0, outfile=sys.stdout): |
---|
1866 | n/a | if node: |
---|
1867 | n/a | # Retrieve info for this node |
---|
1868 | n/a | (nodename,next,prev,up,filename) = node |
---|
1869 | n/a | self.current = nodename |
---|
1870 | n/a | |
---|
1871 | n/a | # Have we been dumped already? |
---|
1872 | n/a | if nodename in self.dumped: |
---|
1873 | n/a | return |
---|
1874 | n/a | self.dumped[nodename] = 1 |
---|
1875 | n/a | |
---|
1876 | n/a | # Print info for this node |
---|
1877 | n/a | print(' '*indent, end=' ', file=outfile) |
---|
1878 | n/a | print('<LI><OBJECT type="text/sitemap">', end=' ', file=outfile) |
---|
1879 | n/a | print('<param name="Name" value="' + nodename +'">', end=' ', file=outfile) |
---|
1880 | n/a | print('<param name="Local" value="'+ filename +'">', end=' ', file=outfile) |
---|
1881 | n/a | print('</OBJECT>', file=outfile) |
---|
1882 | n/a | |
---|
1883 | n/a | # Does this node have menu items? |
---|
1884 | n/a | try: |
---|
1885 | n/a | menu = self.menudict[nodename] |
---|
1886 | n/a | self.dumpmenu(menu,indent+2,outfile) |
---|
1887 | n/a | except KeyError: |
---|
1888 | n/a | pass |
---|
1889 | n/a | |
---|
1890 | n/a | def dumpmenu(self, menu, indent=0, outfile=sys.stdout): |
---|
1891 | n/a | if menu: |
---|
1892 | n/a | currentnode = self.current |
---|
1893 | n/a | if currentnode != self.topnode: # XXX this is a hack |
---|
1894 | n/a | print(' '*indent + '<UL>', file=outfile) |
---|
1895 | n/a | indent += 2 |
---|
1896 | n/a | for item in menu: |
---|
1897 | n/a | menunode = self.getnode(item) |
---|
1898 | n/a | self.dumpnode(menunode,indent,outfile) |
---|
1899 | n/a | if currentnode != self.topnode: # XXX this is a hack |
---|
1900 | n/a | print(' '*indent + '</UL>', file=outfile) |
---|
1901 | n/a | indent -= 2 |
---|
1902 | n/a | |
---|
1903 | n/a | def getnode(self, nodename): |
---|
1904 | n/a | try: |
---|
1905 | n/a | index = self.nodeindex[nodename] |
---|
1906 | n/a | return self.nodelist[index] |
---|
1907 | n/a | except KeyError: |
---|
1908 | n/a | return None |
---|
1909 | n/a | except IndexError: |
---|
1910 | n/a | return None |
---|
1911 | n/a | |
---|
1912 | n/a | # (args,nodename) == (key,location) |
---|
1913 | n/a | def dumpindex(self, outfile=sys.stdout): |
---|
1914 | n/a | print('<UL>', file=outfile) |
---|
1915 | n/a | for (key,location) in self.indexlist: |
---|
1916 | n/a | key = self.codeexpand(key) |
---|
1917 | n/a | location = makefile(location) |
---|
1918 | n/a | location = self.dirname + '/' + location |
---|
1919 | n/a | print('<LI><OBJECT type="text/sitemap">', end=' ', file=outfile) |
---|
1920 | n/a | print('<param name="Name" value="' + key + '">', end=' ', file=outfile) |
---|
1921 | n/a | print('<param name="Local" value="' + location + '">', end=' ', file=outfile) |
---|
1922 | n/a | print('</OBJECT>', file=outfile) |
---|
1923 | n/a | print('</UL>', file=outfile) |
---|
1924 | n/a | |
---|
1925 | n/a | def codeexpand(self, line): |
---|
1926 | n/a | co = self.codeprog.match(line) |
---|
1927 | n/a | if not co: |
---|
1928 | n/a | return line |
---|
1929 | n/a | bgn, end = co.span(0) |
---|
1930 | n/a | a, b = co.span(1) |
---|
1931 | n/a | line = line[:bgn] + line[a:b] + line[end:] |
---|
1932 | n/a | return line |
---|
1933 | n/a | |
---|
1934 | n/a | |
---|
1935 | n/a | # Put @var{} around alphabetic substrings |
---|
1936 | n/a | def makevar(str): |
---|
1937 | n/a | return '@var{'+str+'}' |
---|
1938 | n/a | |
---|
1939 | n/a | |
---|
1940 | n/a | # Split a string in "words" according to findwordend |
---|
1941 | n/a | def splitwords(str, minlength): |
---|
1942 | n/a | words = [] |
---|
1943 | n/a | i = 0 |
---|
1944 | n/a | n = len(str) |
---|
1945 | n/a | while i < n: |
---|
1946 | n/a | while i < n and str[i] in ' \t\n': i = i+1 |
---|
1947 | n/a | if i >= n: break |
---|
1948 | n/a | start = i |
---|
1949 | n/a | i = findwordend(str, i, n) |
---|
1950 | n/a | words.append(str[start:i]) |
---|
1951 | n/a | while len(words) < minlength: words.append('') |
---|
1952 | n/a | return words |
---|
1953 | n/a | |
---|
1954 | n/a | |
---|
1955 | n/a | # Find the end of a "word", matching braces and interpreting @@ @{ @} |
---|
1956 | n/a | fwprog = re.compile('[@{} ]') |
---|
1957 | n/a | def findwordend(str, i, n): |
---|
1958 | n/a | level = 0 |
---|
1959 | n/a | while i < n: |
---|
1960 | n/a | mo = fwprog.search(str, i) |
---|
1961 | n/a | if not mo: |
---|
1962 | n/a | break |
---|
1963 | n/a | i = mo.start() |
---|
1964 | n/a | c = str[i]; i = i+1 |
---|
1965 | n/a | if c == '@': i = i+1 # Next character is not special |
---|
1966 | n/a | elif c == '{': level = level+1 |
---|
1967 | n/a | elif c == '}': level = level-1 |
---|
1968 | n/a | elif c == ' ' and level <= 0: return i-1 |
---|
1969 | n/a | return n |
---|
1970 | n/a | |
---|
1971 | n/a | |
---|
1972 | n/a | # Convert a node name into a file name |
---|
1973 | n/a | def makefile(nodename): |
---|
1974 | n/a | nodename = nodename.strip() |
---|
1975 | n/a | return fixfunnychars(nodename) + '.html' |
---|
1976 | n/a | |
---|
1977 | n/a | |
---|
1978 | n/a | # Characters that are perfectly safe in filenames and hyperlinks |
---|
1979 | n/a | goodchars = string.ascii_letters + string.digits + '!@-=+.' |
---|
1980 | n/a | |
---|
1981 | n/a | # Replace characters that aren't perfectly safe by dashes |
---|
1982 | n/a | # Underscores are bad since Cern HTTPD treats them as delimiters for |
---|
1983 | n/a | # encoding times, so you get mismatches if you compress your files: |
---|
1984 | n/a | # a.html.gz will map to a_b.html.gz |
---|
1985 | n/a | def fixfunnychars(addr): |
---|
1986 | n/a | i = 0 |
---|
1987 | n/a | while i < len(addr): |
---|
1988 | n/a | c = addr[i] |
---|
1989 | n/a | if c not in goodchars: |
---|
1990 | n/a | c = '-' |
---|
1991 | n/a | addr = addr[:i] + c + addr[i+1:] |
---|
1992 | n/a | i = i + len(c) |
---|
1993 | n/a | return addr |
---|
1994 | n/a | |
---|
1995 | n/a | |
---|
1996 | n/a | # Increment a string used as an enumeration |
---|
1997 | n/a | def increment(s): |
---|
1998 | n/a | if not s: |
---|
1999 | n/a | return '1' |
---|
2000 | n/a | for sequence in string.digits, string.ascii_lowercase, string.ascii_uppercase: |
---|
2001 | n/a | lastc = s[-1] |
---|
2002 | n/a | if lastc in sequence: |
---|
2003 | n/a | i = sequence.index(lastc) + 1 |
---|
2004 | n/a | if i >= len(sequence): |
---|
2005 | n/a | if len(s) == 1: |
---|
2006 | n/a | s = sequence[0]*2 |
---|
2007 | n/a | if s == '00': |
---|
2008 | n/a | s = '10' |
---|
2009 | n/a | else: |
---|
2010 | n/a | s = increment(s[:-1]) + sequence[0] |
---|
2011 | n/a | else: |
---|
2012 | n/a | s = s[:-1] + sequence[i] |
---|
2013 | n/a | return s |
---|
2014 | n/a | return s # Don't increment |
---|
2015 | n/a | |
---|
2016 | n/a | |
---|
2017 | n/a | def test(): |
---|
2018 | n/a | import sys |
---|
2019 | n/a | debugging = 0 |
---|
2020 | n/a | print_headers = 0 |
---|
2021 | n/a | cont = 0 |
---|
2022 | n/a | html3 = 0 |
---|
2023 | n/a | htmlhelp = '' |
---|
2024 | n/a | |
---|
2025 | n/a | while sys.argv[1] == ['-d']: |
---|
2026 | n/a | debugging = debugging + 1 |
---|
2027 | n/a | del sys.argv[1] |
---|
2028 | n/a | if sys.argv[1] == '-p': |
---|
2029 | n/a | print_headers = 1 |
---|
2030 | n/a | del sys.argv[1] |
---|
2031 | n/a | if sys.argv[1] == '-c': |
---|
2032 | n/a | cont = 1 |
---|
2033 | n/a | del sys.argv[1] |
---|
2034 | n/a | if sys.argv[1] == '-3': |
---|
2035 | n/a | html3 = 1 |
---|
2036 | n/a | del sys.argv[1] |
---|
2037 | n/a | if sys.argv[1] == '-H': |
---|
2038 | n/a | helpbase = sys.argv[2] |
---|
2039 | n/a | del sys.argv[1:3] |
---|
2040 | n/a | if len(sys.argv) != 3: |
---|
2041 | n/a | print('usage: texi2hh [-d [-d]] [-p] [-c] [-3] [-H htmlhelp]', \ |
---|
2042 | n/a | 'inputfile outputdirectory') |
---|
2043 | n/a | sys.exit(2) |
---|
2044 | n/a | |
---|
2045 | n/a | if html3: |
---|
2046 | n/a | parser = TexinfoParserHTML3() |
---|
2047 | n/a | else: |
---|
2048 | n/a | parser = TexinfoParser() |
---|
2049 | n/a | parser.cont = cont |
---|
2050 | n/a | parser.debugging = debugging |
---|
2051 | n/a | parser.print_headers = print_headers |
---|
2052 | n/a | |
---|
2053 | n/a | file = sys.argv[1] |
---|
2054 | n/a | dirname = sys.argv[2] |
---|
2055 | n/a | parser.setdirname(dirname) |
---|
2056 | n/a | parser.setincludedir(os.path.dirname(file)) |
---|
2057 | n/a | |
---|
2058 | n/a | htmlhelp = HTMLHelp(helpbase, dirname) |
---|
2059 | n/a | parser.sethtmlhelp(htmlhelp) |
---|
2060 | n/a | |
---|
2061 | n/a | try: |
---|
2062 | n/a | fp = open(file, 'r') |
---|
2063 | n/a | except IOError as msg: |
---|
2064 | n/a | print(file, ':', msg) |
---|
2065 | n/a | sys.exit(1) |
---|
2066 | n/a | |
---|
2067 | n/a | parser.parse(fp) |
---|
2068 | n/a | fp.close() |
---|
2069 | n/a | parser.report() |
---|
2070 | n/a | |
---|
2071 | n/a | htmlhelp.finalize() |
---|
2072 | n/a | |
---|
2073 | n/a | |
---|
2074 | n/a | if __name__ == "__main__": |
---|
2075 | n/a | test() |
---|