#reformat python script as HTML comface = "Times New Roman" codeface = "Courier New" import fileinput import sys pagewidth = 118 if len(sys.argv) < 3: print "usage: python tab.py inputfile outputfile" print print x = 0/0 ofil = open(sys.argv[2], "w") #ofil = open("2.txt", "w") ofil.write("") state = "code" #note that formatting characters must be in sequence: #, _, / for o in fileinput.input(sys.argv[1]): oldstate = state if (o[0] == '#') and (o[1] != '*'): #if this line is comment-only state = "comment" top = "" cap = "" if (o[1] == '#') and (o[2] == '#') and (o[3] == '#'): # '####' means big header top += "

" cap += "

" o = o[3:] elif (o[1] == '#') and (o[2] == '#'): # '###' means header top += "

" cap += "

" o = o[2:] if o[1] == '#': # '##' means emphasis on this line top += "" cap += "" o = o[1:] if o[1] == '_': # '_' means underline top += "" cap += "" o = o[1:] if o[1] == '/': # '/" means italics top += "" cap += "" o = o[1:] if state != oldstate: ofil.write('') ofil.write(top + o[1:] + cap + "
") else: state = "code" if (o[0] == '#') and (o[1] == '*'): # '#*' is preformatted comment o = o[2:] # remove them if state != oldstate: ofil.write('
')
    ofil.write(o)

ofil.write("")
ofil.close()