![]() |
#1 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
|
how are nested+contradictory CSS dealt with ?
a line from a calibre conversion with an overkill of styles
Code:
<h1 class="calibre11" id="calibre_pb_34"><span class="calibre12 bold"><strong class="calibre13"><span class="calibre14 calibre15">16</span> KARMIC KILTER</strong></span></h1> in the css, calibre11 thru 15 each have different font size settings. which ones actually get applied to the text ? or to put it another way - how much of that code could be deleted with no side effects ? and do strong and font-weight: bold both do the same thing ? .calibre11 { display: block; font-size: 1.2em; font-weight: bold; line-height: 1.2; margin-bottom: 0.67em; margin-left: 0; margin-right: 0; margin-top: 0.67em; text-align: right } .calibre12 { font-size: 0.8m; line-height: 1.2 } .calibre13 { font-weight: bolder; line-height: 1.2 } .calibre14 { line-height: 1.2 } .calibre15 { color: #BDBDBD; font-size: 1.2em; line-height: 1.2 } final challenge question - a regex which would remove all the unnecessary stuff from that line & from all similar <h1 lines ? Last edited by cybmole; 10-20-2011 at 03:13 AM. |
![]() |
![]() |
![]() |
#2 | ||
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,249
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
|
At the risk of woefully exposing my limited css knowledge, I believe the following to be true:
With nested html elements, the various css attributes are not all treated the same.
Quote:
<strong> and <b> seem to do the same thing. Quote:
<span>, <i>, <em>, <b>, <strong> are inline elements, i.e. they work on a selected portion of a block element. Time to read up on html and css, I think, cybmole ![]() Re: the Regex, I'll leave that for someone else ![]() Last edited by jackie_w; 10-20-2011 at 09:46 PM. Reason: correction re em units |
||
![]() |
![]() |
![]() |
#3 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
|
i did a little experimentation in sigil & + a little googling-
I got the impression that with most attributes the outer one takes preference . so font size is taken from calibre 11 only. could well be though that different programs / readers interpret differently i would strip or comment out colors anyway for e-reader as they are not supported. thanks for the tutorial link. |
![]() |
![]() |
![]() |
#4 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 416
Karma: 1045911
Join Date: Sep 2011
Location: Cape Town, South Africa
Device: Kindle 3
|
Amusing you want to catch all h1/2 etc:
find : <(h\d)[^<>]*>(.+)</\1> replace : <\1>\2</\1> If you are cleaning up books or something, it's often best to work from an HTMLZ export - In the format options you can select how CSS is handled, the 'tag' option will not add any extra stuff, tho I cant remember if it preserves bold/italic etc formatting - i.e placing <i> tags.. |
![]() |
![]() |
![]() |
#5 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
|
Quote:
but I think your code misses the fact that there's both a chapter number and a chapter title within the dross, both of which should ideally be salvaged. |
|
![]() |
![]() |
![]() |
#6 |
US Navy, Retired
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,890
Karma: 13806776
Join Date: Feb 2009
Location: North Carolina
Device: Icarus Illumina XL HD, Kindle PaperWhite SE 11th Gen
|
|
![]() |
![]() |
![]() |
#7 | |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 776
Karma: 2751519
Join Date: Jul 2010
Location: UK
Device: PW2, Nexus7
|
Quote:
(Save/Rename the attached css.txt file as css.html to try it out). Last edited by Agama; 10-21-2011 at 02:29 AM. Reason: Added GIF screenshot to show results |
|
![]() |
![]() |
![]() |
#8 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,791
Karma: 30548723
Join Date: Dec 2006
Location: Singapore
Device: Boyue
|
What kind of ebook needs so many styles. I mostly read fiction so I just convert to text with textile. Then convert to epub from that you can add your custom styles for headings paragraphs italics while converting from text to epub if you are so inclined.
|
![]() |
![]() |
![]() |
#9 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
|
Quote:
I see going to text & back to epub as an absolute last resort. if the source is epub I prefer to retain the original styling, except for tweaking font sizes & centering headers. Sometimes that leads to wanting to clean up the code. I prefer to have everything in the 0.8 - 1.2 em font size range. anything smaller is hard to read & anything larger looks like overkill on the actual e-reader. |
|
![]() |
![]() |
![]() |
#10 |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,914
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
nested spans (or divs) are problematic to replace/remove with REGEX (unless I have been missing a trick
![]() BTW a simple What If I took it out test. /* just comment out the selector in the style sheet */ and see what gets ugly ![]() Unlike CSS errors, undefined styles do not seem to cause problems with ADE on my PEz Last edited by theducks; 10-21-2011 at 08:44 AM. |
![]() |
![]() |
![]() |
#11 | |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 416
Karma: 1045911
Join Date: Sep 2011
Location: Cape Town, South Africa
Device: Kindle 3
|
Quote:
On a more general note : if you're like me and you just like extremely simple - near plain html - books, something that is quite handy would be - this is rather dangerous - read and understand it first. JGsoft syntax: (?<=</?(h\d|[uod]l|[uisbqpa]|hr|abbr|acronym|address|area|base|basefont|bdo|bi g|blockquote|body|button|caption|center|cite|code| col|colgroup|dd|del|dfn|dir|div|dt|em|fieldset|fon t|hr|ins|kbd|label|legend|li|map|object|param|pre| samp|script|select|small|span|strike|strong|sub|su p|table|tbody|td|textarea|tfoot|th|thead|title|tr| tt|var))\s[^<>/]*(?=/?>) replace : blank perl compatible (i.e Python) syntax: (</?)(h\d|[uod]l|[uisbqpa]|hr|abbr|acronym|address|area|base|basefont|bdo|bi g|blockquote|body|button|caption|center|cite|code| col|colgroup|dd|del|dfn|dir|div|dt|em|fieldset|fon t|hr|ins|kbd|label|legend|li|map|object|param|pre| samp|script|select|small|span|strike|strong|sub|su p|table|tbody|td|textarea|tfoot|th|thead|title|tr| tt|var)(\s[^<>/]*)(/?>) replace : \1\2\4 This will strip all attributes from the html tags - i.e : <p class="calibre2"><span class="blarg">This is some text</span></p> becomes: <p><span>This is some text</span></p> You can then apply whatever styles you want directly to all elements - however you usually need two <p> styles - one indented and one flush. Also note that it will remove location markers from your <h1/2..x> headers, so only use this if you plan on regenerating the ToC. You can remove tags from the 'or' list to avoid them entirely - I most likely have forgotten a few header ones in there. If you know the book you're working with also does not contain any 'useful' formatting in the spans, you can use something like : </?span[^/>]*> to remove them all. But read the CSS first, often they are used only to apply italic/bold/underlines - in which case convert those first to their html tags like <i>. All in all it's usually easier to just use the HTMLZ with the CSS set to use tags from the get-go ![]() |
|
![]() |
![]() |
![]() |
#12 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
|
Quote:
I used to always regenerate TOC, but with latest sigil I sometimes leave it mostly as-is, just edit as needed. I find that many novels slip in occasional format changes e,g, for signs, diary/letter extracts, newspaper clippings ... to make than stand out from the general text, & I quite like those. If, when reading, I see anything else that bugs me, I make a note of it using the reader notes facility then do an additional post-read edit. I do that also for annoying typos. |
|
![]() |
![]() |
![]() |
#13 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,226
Karma: 145488788
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Maybe one built from an MS Word document.
|
![]() |
![]() |
![]() |
#14 | ||
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 416
Karma: 1045911
Join Date: Sep 2011
Location: Cape Town, South Africa
Device: Kindle 3
|
Quote:
Quote:
Scifi conversions nearly always have their letters/signs etc messed up during conversion, especially when print books use a teletype style for them. So I spend a lot of time putting in <tt>'s. Yay. |
||
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Has any dealt with this company? | kenm | Android Devices | 3 | 10-14-2010 09:05 AM |
NCX creation -- nested or not, css classes | illustrata | ePub | 3 | 08-25-2010 08:56 AM |
Has anybody ever dealt with this web store? | pathfinderca | Alternative Devices | 5 | 12-03-2009 04:34 PM |
Contradictory error messages in ConvertLit | Fledchen | Workshop | 6 | 02-21-2009 12:38 PM |