peps: 1721d9c7a378 (original) (raw)
Mercurial > peps
changeset 23:1721d9c7a378
incorporating changes from /F not including pep-0000.txt -> index.html (a symbolic link does just fine)
Peter Schneider-Kamp nowonder@nowonder.de | |
---|---|
date | Thu, 20 Jul 2000 22:44:36 +0000 |
parents | fd8bca46c698 |
children | 109f5829f49a |
files | pep2html.py |
diffstat | 1 files changed, 32 insertions(+), 8 deletions(-)[+] [-] pep2html.py 40 |
line wrap: on
line diff
--- a/pep2html.py +++ b/pep2html.py @@ -10,7 +10,13 @@ to the web pages at source forge. import cgi, glob, os, re, sys -fixpat = re.compile("((http|ftp):[-_a-zA-Z0-9/.+?~:#$]+)|(pep-\d+(.txt)?)|.") +# this doesn't validate -- you cannot use
and
inside
+# tags. but if I change that, the result doesn't look very nice...
+
+DTD = ('
'"http://www.w3.org/TR/REC-html40/loose.dtd">')[](#l1.12)
'"http://www.w3.org/TR/REC-html40/loose.dtd">')[](#l1.12)
+ +fixpat = re.compile("((http|ftp):[-_a-zA-Z0-9/.+~:?#$=&]+)|(pep-\d+(.txt)?)|.") def fixanchor(match): text = match.group(0) @@ -21,16 +27,18 @@ def fixanchor(match): link = os.path.splitext(text)[0] + ".html" if link: return "%s" % (link, cgi.escape(link))
def fixfile(infile, outfile): # convert plain text pep to minimal XHTML markup fi = open(infile) fo = open(outfile, "w")
- fo.write("%s\n\n" % DTD)
header = [] head fo.write("\n")
- pep = ""
- title = "" while 1: line = fi.readline() if not line or ":" not in line:
@@ -39,11 +47,22 @@ def fixfile(infile, outfile): value = value.strip() header.append((key, value)) if key.lower() == "title":
fo.write("<title>%s</title>\n" % cgi.escape(value))[](#l1.43)
title = value[](#l1.44)
if key.lower() == "pep":[](#l1.45)
pep = value[](#l1.46)
- if pep:
title = "PEP " + pep + " -- " + title[](#l1.48)
- if title:
fo.write("\n")fo.write("<title>%s</title>\n" % cgi.escape(title))[](#l1.50)
fo.write("\n") body fo.write("
\n")
- fo.write("[home]")
- if os.path.basename(file) != "pep-0000.txt":
fo.write(" [<a href='.'>index</a>]")[](#l1.57)
- fo.write("\n
\n") fo.write("\n
\n")for k, v in header: fo.write("%s: %s\n" % (cgi.escape(k), cgi.escape(v))) title = 0 @@ -52,15 +71,20 @@ def fixfile(infile, outfile): if not line: break if line[:1] == "\f":
fo.write("<hr />\n")[](#l1.67)
fo.write("\n<hr />\n")[](#l1.68)
# fo.write("\n</pre><hr /><pre>\n")[](#l1.69) title = 1[](#l1.70)
else:[](#l1.71)
elif title >= 0:[](#l1.72) line = fixpat.sub(fixanchor, line)[](#l1.73) if title:[](#l1.74)
fo.write("<h3>%s</h3>\n" % line)[](#l1.75)
if line.strip() == "Local Variables:":[](#l1.76)
title = -1[](#l1.77)
else:[](#l1.78)
fo.write("<h3><tt>%s</tt></h3>\n" % line)[](#l1.79)
# fo.write("</pre><h3><tt>%s</tt></h3><pre>\n" % line)[](#l1.80)
title = 0[](#l1.81) else:[](#l1.82) fo.write(line)[](#l1.83)
fo.write("title = 0[](#l1.84)