From: Handzsuj,Thomas <tho...@dr...> - 2002-11-08 10:34:21
|
Hi, I have a suggestion for using ht2html together with docutils (http://docutils.sourceforge.net/) The advantage is that I have to deal only with simple and readable = ASCII files. The problem is that docutils creates normal html files. The information = in the header of these files (e.g. title, charset) is lost if I use them = as ht files. To transfer this information I wrote a simple Parser based on = SGMLParser. It collects information from the body and the get_.. functions take this information. (My generator is based on PDOGenerator.py) Here it is: class extraParser(SGMLParser): def __init__(self): SGMLParser.__init__(self) self.text =3D '' self.startRec =3D 0 =20 def start_title(self, attrs): self.startRec =3D 1 def end_title(self): self.title =3D self.text self.startRec =3D 0 def start_meta(self,attrs): for k,v in attrs: if k=3D=3D'content' and v.find('charset') >=3D 0: self.charset =3D v.split('=3D')[1] def handle_data(self, text): if self.startRec: self.text +=3D text else: self.text +=3D '' It is used after reading the body (in __grokbody of my generator): self.__extraParser.feed(text) self.__extraParser.close() Information is used like this: def get_title(self): try: return self.__extraParser.title except AttributeError: return self.__parser.get('title') Best regards / Mit freundlichen Gr=FC=DFen=20 Thomas Handzsuj Design and Development Intensive Care ---------------------------------------------------- DR=C4GER MEDICAL Dr=E4ger Medical AG & Co. KGaA Moislinger Allee 53-55 D-23542 L=FCbeck Tel: + 49-451-882-1524 Fax: + 49-451-882-71524 (PC) Fax: + 49-451-882-2856 (paper print) ----------------------------------------------------- |