View Single Post
Old 06-19-2011, 06:36 AM   #107
ldolse
Wizard
ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.
 
Posts: 1,337
Karma: 123455
Join Date: Apr 2009
Location: Malaysia
Device: PRS-650, iPhone
Kovid might be better able to comment on this, but I believe you can use cssutils (already bundled into Calibre) to parse the css canonically - i.e. you wouldn't need to worry about all the potential string level variations in the css file. I've never worked with cssutils myself, so I'm not 100% sure it's applicable.

Docs:
http://cssutils.googlecode.com/svn/t.../docs/css.html

If you're just going to parse as a string then I suppose the trick would be to look for 'body' or 'page' and then grab the text between the next pair of open and closing brackets. Then either delete or zero any margins that are set.


Anyway here's an example:
Code:
.tp {  
margin-top: 1em;
margin-bottom: 1em;
margin-left: -.4em;
text-align: center;
}

@page { margin-bottom: 1em;margin-left: 1em;margin-right: 1em;margin-top: 1em;}
body { margin-bottom: 1em;margin-left: 1.5em;margin-right: 1.5em;margin-top: 1em;}
.center { text-align:center; }

.small {
  font-size: -1em;
}
And the margins could either be zero'd out like this:
Code:
.tp {  
margin-top: 1em;
margin-bottom: 1em;
margin-left: -.4em;
text-align: center;
}

@page { margin-bottom: 0em;margin-left: 0em;margin-right: 0em;margin-top: 0em;}
body { margin-bottom: 0em;margin-left: 0em;margin-right: 0em;margin-top: 0em;}
.center { text-align:center; }

.small {
  font-size: -1em;
}
Or just deleted altogether:
Code:
.tp {  
margin-top: 1em;
margin-bottom: 1em;
margin-left: -.4em;
text-align: center;
}

@page { }
body { }
.center { text-align:center; }

.small {
  font-size: -1em;
}
ldolse is offline   Reply With Quote