![]() |
#1 |
Enthusiast
![]() Posts: 34
Karma: 10
Join Date: Aug 2011
Device: Amazon Kindle 3
|
Extra CSS and class renaming
Hi, I wrote recipe for page which has "aligncenter" class for image. I don't use its CSS (no_stylesheets = True), but I wrote extra_css = '.aligncenter {display: block; margin-left: auto; margin-right: auto;}'. Problem is that calibre changes class name from "aligncenter" to "aligncenter1", next class occurrence is renamed to "aligncenter2" etc.
I used debug option to check where renaming is done. Input and parsed html has correct class names, but processed html has changed class name, so my extra_css do not work and I'm not changing it. Is this some kind of bug or this is intended and how to make extra_css work? Thanks. |
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,195
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
extra css is applied before class names are changed. You need to override the particular style not just the class as otherwise classes are merged. So you need
text-align:justify or whatever in your .aligncenter definition. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Enthusiast
![]() Posts: 34
Karma: 10
Join Date: Aug 2011
Device: Amazon Kindle 3
|
Thank you for advice, Kovid. Unfortunately this don't solve my problem.
Let's say I have this tag: Code:
<img class="alignright size-medium wp-image-48200" width="250" height="360" src="image-48200.png" alt="title" style="width: 250px; height: 360px;"></img> Code:
float: right; margin: 0px 0px 5px 10px; Code:
extra_css = '.alignright {float: right; margin: 0px 0px 5px 10px;}' Code:
remove_attributes = ['width', 'height'] There's one more problem. It seams that calibre preserves only first class name. If class string of an element will be "size-medium alignright wp-image-48200" instead of "alignright size-medium wp-image-48200" then in output ebook this element won't have alignright class as expected but size-medium. Here's a full recipe if you want to test it yourself or found my explanation not clear enough: Spoiler:
|
![]() |
![]() |
![]() |
#4 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,195
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
class renaming is irrelevant. calibre does not care about class names. It merges styles using css selector specificity and once all the merging is done it then generates new class names for the merged styles.
If your extra css is not not being applied to the second image it is not because its class name is changed, it will be for some other reason. I dont have the time to look at it right now, but if you just want to hack it, simply add code to remove the classnames you dont want from the images' class attribute to postprocess_html in your recipe. |
![]() |
![]() |
![]() |
#5 |
Enthusiast
![]() Posts: 34
Karma: 10
Join Date: Aug 2011
Device: Amazon Kindle 3
|
I see. Changing classes in postprocess_html works but css is still not applied. I have to add inline style myself:
Code:
def postprocess_html(self, soup, first_fetch): for tag in soup.findAll(attrs={'class':re.compile('alignright')}): tag['class'] = 'alignright' tag['style'] = 'float: right; margin: 0px 0px 5px 10px;' for tag in soup.findAll(attrs={'class':re.compile('alignleft')}): tag['class'] = 'alignleft' tag['style'] = 'float:left; margin-right:5px;' for tag in soup.findAll(attrs={'class':re.compile('aligncenter')}): tag['class'] = 'aligncenter' tag['style'] = 'margin: 0px auto; display: block;' return soup |
![]() |
![]() |
Advert | |
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Adding body style to Extra CSS does nothing | Barty | Conversion | 7 | 10-23-2013 11:06 PM |
--extra-css doesn't seem to work | dawood | Conversion | 4 | 10-19-2013 09:23 AM |
Justification problem even with extra css | hiperlink | Recipes | 2 | 03-09-2011 08:40 AM |
css pseudo elements and adjacent combinators in extra css? | ldolse | Calibre | 2 | 12-21-2010 05:09 PM |
a few extra css questions | marbs | Recipes | 12 | 11-20-2010 10:15 AM |