View Single Post
Old 04-29-2013, 02:39 PM   #10
hegi
Enthusiast
hegi began at the beginning.
 
Posts: 44
Karma: 10
Join Date: Dec 2012
Device: Kindle 4 & Kindle PW 3G
Question preprocess_html instead of extra_css

Hiho,

... still optimizing ... and still going a bit crazy, since I have only superficial programming skills.

Now, if the clever CSS hint from Kovid won't work for .mobi format, I ask myself, if I could not achieve the same using preprocess_html. What I get as input form the webiste is:

Code:
<span class="hcf-location-mark">Place</span>
In order to add a ". " after "Place" can't I do something like:

Code:
    def preprocess_html(self, soup):
        for location in soup.find('span', attrs={'class':'hcf-location-mark'}):
                newloc = location.string +". "
                location.replaceWith(newloc)
        return soup
This is "reverse-engineering" from other recipes. So please don't hit me if the syntax is a bit foolish, OK? - But I coudn't find this kind of "search and replace" expample elsewhere yet.

Thanks.

Hegi.
hegi is offline   Reply With Quote