View Single Post
Old 12-02-2009, 01:57 PM   #53
macr0t0r
Connoisseur
macr0t0r doesn't littermacr0t0r doesn't litter
 
macr0t0r's Avatar
 
Posts: 91
Karma: 108
Join Date: Jan 2008
Device: Palm Treo 680, Sony Reader
Okay, this manual editing thing is for the birds, so I'll offer some code to handle the conversion of special characters automatically. Obviously, I'm not going to post any illegal material, so you'll have to do the modifications yourself.

First off, add this definition right about the " def getText(self):" definition:
Code:
    def cleanPML(self,pml)
        # Update old \b font tag with correct \B bold font tag
        pml2 = pml.replace('\\b', '\\B')
        # Convert special characters to proper PML code.  High ASCII start at (\x82, \a130) and go up to (\xff, \a255)
        for k in xrange(130,256):
            # a2b_hex takes in a hexidecimal as a string and converts it to a binary ascii code that we search and replace for
            badChar=binascii.a2b_hex('%02x' % k)
            pml2 = pml2.replace(badChar, '\\a%03d' % k)
        #end for k
        return pml2
Make sure you use spaces instead of tabs for indents. Now, change any line with:
Code:
zlib.decompress(....
to:
Code:
self.cleanPML(zlib.decompress(...
That will automatically fix all of the special characters. Mind you, it will run a little slower, but it's still faster than manual editing! I actually use this bit of code when cleaning up my OpenOffice-generated files before converting them to use on my Palm. (Yes, I still use a Palm. What?)

- Jim

Last edited by macr0t0r; 12-02-2009 at 02:02 PM.
macr0t0r is offline   Reply With Quote