#!/usr/bin/env pythonx #-*- coding: UTF-8 -*- '''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) # recently switched to latex2html, now cutting of headers # dieser abschnitt muss ueberarbeitet werden! startoffset=string.find(content,"
\n
") endoffset=string.find(content,"
",startoffset)+len("") 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,"

\n\n",'') content = string.replace(content,"",'') #remove empty image subtitles content = string.replace(content,"Abbildung:","") #Bereich "author_info": Entfernen der Formatierung startoffset=string.find(content,'
",startoffset)+len("") if (startoffset >10) and (endoffset>startoffset): content=string.replace(content,'

',"

") content=string.replace(content,"","") content=string.replace(content,"","") #TOC formatieren - Der Abschnitt muss noch allgemeiner werden content = string.replace(content,'
\n\n

\nInhalt\n

\n','\n
\n
Auf dieser Seite:
') content = string.replace(content,"","
") # replace "./filename.png" references with "filename.png" # (this avoids validation warnings) content = string.replace(content,'HREF="./','HREF="') # Fussnoten finden und Ende ersetzen fussnoten = string.find(content,"

Fußnoten

") startoffset = string.find(content,"",fussnoten) endoffset = startoffset + len("") if startoffset > 10 and endoffset > 10: content = content[:startoffset] + "\n
" + content[endoffset:] # Linie vor Fussnoten wird entfernt # Fussnoten bekommen id, damit sie per css formatierbar sind content = string.replace(content,'

Fußnoten

','\n
\n
Fußnoten
') # Sonderzeichen in Fussnoten werden ersetzt (Hotfix fuer einen latex2html-Bug) content = string.replace(content,'ä','ä') content = string.replace(content,'Ä','Ä') content = string.replace(content,'ö','ö') content = string.replace(content,'Ö','Ö') content = string.replace(content,'ü','ü') content = string.replace(content,'Ü','Ü') content = string.replace(content,'ß','ß') # externe Links innerhalb von
erhalten eine class content = string.replace(content,'HREF="http:','class="externalLink" href="http:') content = string.replace(content,'HREF="https:','class="externalLink" href="https:') #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],"" sys.exit(1) sys.exit(0)