View Single Post
Old 09-28-2010, 11:32 PM   #2
TonytheBookworm
Addict
TonytheBookworm is on a distinguished road
 
TonytheBookworm's Avatar
 
Posts: 264
Karma: 62
Join Date: May 2010
Device: kindle 2, kindle 3, Kindle fire
Quote:
Originally Posted by jefferson_frantz View Post
Hello everyone. I'm new with calibre recipes and i need some help with a recipe for 'Muy Interesante' magazine (http://www.muyinteresante.es).
First, i want to change the style for the title of the articles, maybe just to put in bold style.
Second, i need to insert a <br> tag after the image in the article, so the text appears below the image and not next to it. The attached image maybe explain better what i want

Thanks in advance!.

Here is my recipe:



PS: Sorry about my english


as for the image thing do something like this
Spoiler:

Code:
def preprocess_html(self, soup):
        for img_tag in soup.findAll('img'):
            parent_tag = img_tag.parent
            if parent_tag.name == 'a':
                new_tag = Tag(soup,'p')
                new_tag.insert(0,img_tag)
                parent_tag.replaceWith(new_tag)
            elif parent_tag.name == 'p':
                if not self.tag_to_string(parent_tag) == '':
                    new_div = Tag(soup,'div')
                    new_tag = Tag(soup,'p')
                    new_tag.insert(0,img_tag)
                    parent_tag.replaceWith(new_div)
                    new_div.insert(0,new_tag)
                    new_div.insert(1,parent_tag)
        return soup


and as for the bold title or whatever you add extra_css
so lets say your title was in a <div class='title'>..... </div> tag and you wanted it different
you would do this:
Spoiler:

Code:
#first we need to turn off style sheets so we do this:
no_stylesheets = True

#then we add our own style(s) like this:
extra_css = '''
                   
                   .Title{font-weight: bold; font-size: xx-large}
                   p {font-size: 4px;font-family: Times New Roman;}
                '''



###########################################################
#this right here gets rid of all the inline styles that prevent extra_css from working a lot 
#of times....
###########################################################
def preprocess_html(self, soup):
        for item in soup.findAll(style=True):
           del item['style']
        return soup

Last edited by TonytheBookworm; 09-28-2010 at 11:44 PM.
TonytheBookworm is offline   Reply With Quote