2005-04-23 22:35:52 +02:00
|
|
|
|
#!/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()
|
2005-05-13 12:04:02 +02:00
|
|
|
|
|
|
|
|
|
# zu_manipulierende_variable=string.replace(zu_manipulierende_variable,alter_string,neuer_string)
|
|
|
|
|
|
|
|
|
|
# recently switched to latex2html, now cutting of headers
|
2005-05-13 10:40:22 +02:00
|
|
|
|
# dieser abschnitt muss ueberarbeitet werden!
|
2005-04-23 22:35:52 +02:00
|
|
|
|
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,"")
|
|
|
|
|
|
|
|
|
|
#put whole content into div tags
|
|
|
|
|
content = string.replace(content,"</BODY>",'</div>')
|
|
|
|
|
content = string.replace(content,"</HTML>",'<!-- end of main -->')
|
|
|
|
|
|
|
|
|
|
#remove empty image subtitles
|
2005-05-13 11:19:10 +02:00
|
|
|
|
content = string.replace(content,"<STRONG>Abbildung:</STRONG>","")
|
2005-04-23 22:35:52 +02:00
|
|
|
|
|
2006-06-10 12:29:09 +02:00
|
|
|
|
# replace "./filename.png" references with "filename.png"
|
|
|
|
|
# (this avoids validation warnings)
|
|
|
|
|
content = string.replace(content,'HREF="./','HREF="')
|
2006-06-12 15:40:15 +02:00
|
|
|
|
|
2006-06-15 14:23:28 +02:00
|
|
|
|
# Fussnoten finden und Ende ersetzen
|
|
|
|
|
fussnoten = string.find(content,"<BR><HR><H4>Fußnoten</H4>")
|
|
|
|
|
startoffset = string.find(content,"</DL>\n<BR><HR>",fussnoten)
|
|
|
|
|
endoffset = startoffset + len("</DL>\n<BR><HR>")
|
|
|
|
|
content = content[:startoffset] + "</DL>\n</div>" + content[endoffset:]
|
|
|
|
|
|
2006-06-12 15:55:11 +02:00
|
|
|
|
# Linie vor Fussnoten wird entfernt
|
2006-06-12 15:40:15 +02:00
|
|
|
|
# Fussnoten bekommen id, damit sie per css formatierbar sind
|
2006-06-15 14:23:28 +02:00
|
|
|
|
content = string.replace(content,'<HR><H4>Fußnoten</H4>','\n<div id="footnotes">\n<H4>Fußnoten</H4>')
|
2006-06-13 09:38:42 +02:00
|
|
|
|
|
|
|
|
|
# Sonderzeichen in Fussnoten werden ersetzt (Hotfix fuer einen latex2html-Bug)
|
|
|
|
|
content = string.replace(content,'<EFBFBD>','ä')
|
|
|
|
|
content = string.replace(content,'<EFBFBD>','Ä')
|
|
|
|
|
content = string.replace(content,'<EFBFBD>','ö')
|
|
|
|
|
content = string.replace(content,'<EFBFBD>','Ö')
|
|
|
|
|
content = string.replace(content,'<EFBFBD>','ü')
|
|
|
|
|
content = string.replace(content,'<EFBFBD>','Ü')
|
|
|
|
|
content = string.replace(content,'<EFBFBD>','ß')
|
2006-06-15 12:45:42 +02:00
|
|
|
|
|
2006-06-15 13:09:10 +02:00
|
|
|
|
# externe Links innerhalb von <div id="main"> erhalten eine class
|
|
|
|
|
content = string.replace(content,'HREF="http:','class="externalLink" href="http:')
|
2006-06-10 12:29:09 +02:00
|
|
|
|
|
2005-04-23 22:35:52 +02:00
|
|
|
|
#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)
|