annotate Misc/faq2html.py @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents 73758db2f464
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4573
73758db2f464 /usr/local/bin/python -> /usr/bin/env python
Guido van Rossum <guido@python.org>
parents: 4265
diff changeset
1 #! /usr/bin/env python
2069
3aa7a7784455 New file -- creates FAQ.html.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
4265
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
3 # A somewhat-generalized FAQ-to-HTML converter (by Ka-Ping Yee, 10 Sept 96)
2069
3aa7a7784455 New file -- creates FAQ.html.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
4265
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
5 # Reads a text file given on standard input or named as first argument, and
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
6 # generates HTML 2.0 on standard output. Recognizes these constructions:
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
7 #
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
8 # HTML element pattern at the beginning of a line
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
9 #
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
10 # section heading (<number><period>)+<space>
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
11 # numbered list element <1-2 spaces>(<number><period>)+<space>
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
12 # unnumbered list element <0-2 spaces><hyphen or asterisk><space>
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
13 # preformatted section <more than two spaces>
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
14 #
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
15 # Heading level is determined by the number of (<number><period>) segments.
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
16 # Blank lines force a separation of elements; if none of the above four
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
17 # types is indicated, a new paragraph begins. A line beginning with many
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
18 # spaces is interpreted as a continuation (instead of preformatted) after
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
19 # a list element. Headings are anchored; paragraphs starting with "Q." are
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
20 # emphasized, and those marked with "A." get their first sentence emphasized.
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
21 #
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
22 # Hyperlinks are created from references to:
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
23 # URLs, explicitly marked using <URL:scheme://host...>
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
24 # other questions, of the form "question <number>(<period><number>)*"
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
25 # sections, of the form "section <number>".
2069
3aa7a7784455 New file -- creates FAQ.html.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
4265
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
27 import sys, string, regex, regsub, regex_syntax
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
28 regex.set_syntax(regex_syntax.RE_SYNTAX_AWK)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
29
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
30 # --------------------------------------------------------- regular expressions
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
31 orditemprog = regex.compile(' ?([1-9][0-9]*\.)+ +')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
32 itemprog = regex.compile(' ? ?[-*] +')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
33 headingprog = regex.compile('([1-9][0-9]*\.)+ +')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
34 prefmtprog = regex.compile(' ')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
35 blankprog = regex.compile('^[ \t\r\n]$')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
36 questionprog = regex.compile(' *Q\. +')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
37 answerprog = regex.compile(' *A\. +')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
38 sentprog = regex.compile('(([^.:;?!(]|[.:;?!][^ \t\r\n])+[.:;?!]?)')
2069
3aa7a7784455 New file -- creates FAQ.html.
Guido van Rossum <guido@python.org>
parents:
diff changeset
39
4265
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
40 mailhdrprog = regex.compile('^(Subject|Newsgroups|Followup-To|From|Reply-To'
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
41 '|Approved|Archive-Name|Version|Last-Modified): +', regex.casefold)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
42 urlprog = regex.compile('&lt;URL:([^&]+)&gt;')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
43 addrprog = regex.compile('&lt;([^>@:]+@[^&@:]+)&gt;')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
44 qrefprog = regex.compile('question +([1-9](\.[0-9]+)*)')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
45 srefprog = regex.compile('section +([1-9][0-9]*)')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
46 entityprog = regex.compile('[&<>]')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
47
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
48 # ------------------------------------------------------------ global variables
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
49 body = []
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
50 ollev = ullev = 0
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
51 element = content = secnum = version = ''
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
52
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
53 # ----------------------------------------------------- for making nested lists
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
54 def dnol():
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
55 global body, ollev
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
56 ollev = ollev + 1
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
57 if body[-1] == '</li>': del body[-1]
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
58 body.append('<ol>')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
59
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
60 def upol():
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
61 global body, ollev
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
62 ollev = ollev - 1
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
63 body.append(ollev and '</ol></li>' or '</ol>')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
64
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
65 # --------------------------------- output one element and convert its contents
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
66 def spew(clearol=0, clearul=0):
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
67 global content, body, ollev, ullev
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
68
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
69 if content:
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
70 if entityprog.search(content) > -1:
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
71 content = regsub.gsub('&', '&amp;', content)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
72 content = regsub.gsub('<', '&lt;', content)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
73 content = regsub.gsub('>', '&gt;', content)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
74
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
75 n = questionprog.match(content)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
76 if n > 0:
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
77 content = '<em>' + content[n:] + '</em>'
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
78 if ollev: # question reference in index
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
79 fragid = regsub.gsub('^ +|\.? +$', '', secnum)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
80 content = '<a href="#%s">%s</a>' % (fragid, content)
2069
3aa7a7784455 New file -- creates FAQ.html.
Guido van Rossum <guido@python.org>
parents:
diff changeset
81
4265
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
82 if element[0] == 'h': # heading in the main text
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
83 fragid = regsub.gsub('^ +|\.? +$', '', secnum)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
84 content = secnum + '<a name="%s">%s</a>' % (fragid, content)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
85
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
86 n = answerprog.match(content)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
87 if n > 0: # answer paragraph
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
88 content = regsub.sub(sentprog, '<strong>\\1</strong>', content[n:])
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
89
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
90 body.append('<' + element + '>' + content)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
91 body.append('</' + element + '>')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
92 content = ''
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
93
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
94 while clearol and ollev: upol()
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
95 if clearul and ullev: body.append('</ul>'); ullev = 0
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
96
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
97 # ---------------------------------------------------------------- main program
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
98 faq = len(sys.argv)>1 and sys.argv[1] and open(sys.argv[1]) or sys.stdin
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
99 lines = faq.readlines()
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
100
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
101 for line in lines:
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
102 if line[2:9] == '=======': # <hr> will appear *before*
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
103 body.append('<hr>') # the underlined heading
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
104 continue
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
105
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
106 n = orditemprog.match(line)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
107 if n > 0: # make ordered list item
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
108 spew(0, 'clear ul')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
109 secnum = line[:n]
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
110 level = string.count(secnum, '.')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
111 while level > ollev: dnol()
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
112 while level < ollev: upol()
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
113 element, content = 'li', line[n:]
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
114 continue
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
115
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
116 n = itemprog.match(line)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
117 if n > 0: # make unordered list item
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
118 spew('clear ol', 0)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
119 if ullev == 0: body.append('<ul>'); ullev = 1
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
120 element, content = 'li', line[n:]
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
121 continue
2069
3aa7a7784455 New file -- creates FAQ.html.
Guido van Rossum <guido@python.org>
parents:
diff changeset
122
4265
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
123 n = headingprog.match(line)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
124 if n > 0: # make heading element
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
125 spew('clear ol', 'clear ul')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
126 secnum = line[:n]
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
127 sys.stderr.write(line)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
128 element, content = 'h%d' % string.count(secnum, '.'), line[n:]
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
129 continue
2069
3aa7a7784455 New file -- creates FAQ.html.
Guido van Rossum <guido@python.org>
parents:
diff changeset
130
4265
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
131 n = 0
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
132 if not secnum: # haven't hit body yet
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
133 n = mailhdrprog.match(line)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
134 v = version and -1 or regex.match('Version: ', line)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
135 if v > 0 and not version: version = line[v:]
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
136 if n <= 0 and element != 'li': # not pre if after a list item
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
137 n = prefmtprog.match(line)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
138 if n > 0: # make preformatted element
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
139 if element == 'pre':
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
140 content = content + line
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
141 else:
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
142 spew('clear ol', 'clear ul')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
143 element, content = 'pre', line
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
144 continue
2069
3aa7a7784455 New file -- creates FAQ.html.
Guido van Rossum <guido@python.org>
parents:
diff changeset
145
4265
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
146 if blankprog.match(line) > 0: # force a new element
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
147 spew()
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
148 element = ''
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
149 elif element: # continue current element
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
150 content = content + line
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
151 else: # no element; make paragraph
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
152 spew('clear ol', 'clear ul')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
153 element, content = 'p', line
2069
3aa7a7784455 New file -- creates FAQ.html.
Guido van Rossum <guido@python.org>
parents:
diff changeset
154
4265
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
155 spew() # output last element
2069
3aa7a7784455 New file -- creates FAQ.html.
Guido van Rossum <guido@python.org>
parents:
diff changeset
156
4265
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
157 body = string.joinfields(body, '')
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
158 body = regsub.gsub(urlprog, '<a href="\\1">\\1</a>', body)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
159 body = regsub.gsub(addrprog, '<a href="mailto:\\1">\\1</a>', body)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
160 body = regsub.gsub(qrefprog, '<a href="#\\1">question \\1</a>', body)
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
161 body = regsub.gsub(srefprog, '<a href="#\\1">section \\1</a>', body)
2069
3aa7a7784455 New file -- creates FAQ.html.
Guido van Rossum <guido@python.org>
parents:
diff changeset
162
4265
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
163 print '<!doctype html public "-//IETF//DTD HTML 2.0//EN"><html>'
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
164 print '<head><title>Python Frequently-Asked Questions v' + version
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
165 print "</title></head><body>(This file was generated using Ping's"
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
166 print '<a href="faq2html.py">faq2html.py</a>.)'
8892da9554a5 Rewritten by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 2662
diff changeset
167 print body + '</body></html>'