cryptocd/documents/mod_html_files.py
phil 22f12b3e87 mod_html fussnoten-string berichtigt
latex2html-experimente mit winpt (keine weiteren veranderungen)
2005-05-13 09:47:40 +00:00

61 lines
1.8 KiB
Python

#!/usr/bin/env python
'''gets a latex2html file and returns the file with a css tag
and stuff'''
import string
import sys
import re
def writeFile(data, filename):
"""
write data to the given filename
@param filename String : name of file to write to
"""
try:
f = open(filename,"w")#oeffnen und schliessen =>
f.close() #datei ist jetzt genullt
f = open(filename,"a") #anhaengend oeffnen
f.write(data)
f.close()
return ""
except:
print "(WW)[%s]: \"%s\" is not writeable!"%(__name__, filename)
return filename
### start of code
try:
f=open(sys.argv[1],"r")
content=f.read()
f.close()
#zu_manipulierende_variable=string.replace(zu_manipulierende_variable,alter_string,neuer_string)
content=string.replace(content,'Table of Contents','Inhalt')
#recently switched to latex2html, now cutting of headers
# dieser abschnitt muss ueberarbeitet werden!
startoffset=string.find(content,"<HR>\n<ADDRESS>")
endoffset=string.find(content,"</ADDRESS>",startoffset)+len("</ADDRESS>")
if (startoffset >10) and (endoffset>startoffset):
footer=content[startoffset:endoffset]
content=string.replace(content,footer,"")
#rename footnotes into Fussnoten
content = string.replace(content,"Fußnoten","Fussnoten")
#put whole content into div tags
content = string.replace(content,"<BODY >",'<BODY>\n<!-- main starts here -->\n<div id="main">')
content = string.replace(content,"</BODY>",'</div>')
content = string.replace(content,"</HTML>",'<!-- end of main -->')
#remove empty image subtitles
content = string.replace(content,"<STRONG>Abbildung:</STRONG>","")
#all done, writing tuned files
writeFile(content,sys.argv[1])
except: #read/write/whatever failed,
# BOESE: unklare Fehlerbehandlung
print "an defined error occured - but i'm too lame to fix that"
print "usage:",sys.argv[0],"<file_to_modify>"
sys.exit(1)
sys.exit(0)