[xiph-cvs] cvs commit: theora/doc spec2html.py
Ralph Giles
giles at xiph.org
Thu Jul 10 04:40:54 PDT 2003
giles 03/07/10 07:40:53
Added: doc spec2html.py
Log:
Add a quick script to generate spec.html from spec.py. Dan claims to have used such a script for the original version, but I can't figure out what some of the formatting keys are, so this isn't turned on yet. We should use Restructured Text anyway.
Revision Changes Path
1.1 theora/doc/spec2html.py
Index: spec2html.py
===================================================================
#!/usr/bin/env python
import string
class htmlthing:
'''handle writing out a simple formatted html file'''
def __init__(self,filename):
self.filename = filename
self.title = ""
self.starts = { 'pre': "<pre>", 'normal': "<p>\n", 'h1': "\n<h1>", 'h2': "<h2>" }
self.ends = { 'pre' : "</pre>\n", 'normal': "</p>\n", 'h1': "</h1>\n", 'h2': "</h2>\n" }
self.state = 'none'
def set_title(self, title):
self.title = title
def open(self):
self.file = open(self.filename, 'w')
self.write_header()
def close(self):
self.write_footer()
self.file.close()
def write_header(self):
self.file.write("<html>\n<head>\n")
if self.title:
self.file.write("<title>" + self.title + "</title>\n")
self.file.write("<!-- generated by spec2html from source -->\n")
self.file.write("</head>\n<body>\n")
def write_footer(self):
self.file.write("\n</body>\n</html>\n")
def close_group(self):
if self.state != 'none':
self.file.write(self.ends[self.state])
self.state = 'none'
def set_state(self, state):
if self.state != state:
self.close_group()
self.file.write(self.starts[state])
self.state = state
def write(self, line):
self.file.write(line)
pec = open('spec.py', 'r')
html = htmlthing('spec.html')
html.open()
blank_count = 0;
while True:
line = spec.readline()
if line == '': break
if line == '\n':
html.close_group()
blank_count += 1
else:
if line[:1] == '#':
if line[:4] == '# ':
html.set_state('pre')
elif line[:3] == '##_':
html.set_state('h1')
line = line[:1] + line[3:-1]
elif blank_count > 1:
html.set_state('h2')
line = string.strip(line)
else:
html.set_state('normal')
html.write(line[1:])
else:
html.set_state('pre')
html.write(line)
blank_count = 0
html.close()
spec.close()
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list