Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old Yesterday, 03:01 PM   #1
enuddleyarbl
Guru
enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.
 
enuddleyarbl's Avatar
 
Posts: 911
Karma: 2111023
Join Date: Sep 2013
Device: Kobo Sage
Am I Misunderstanding Nesting Selectors?

EDIT: OK. It looks like I don't need the actual & since I want the rule to apply to all descendents. If I pull it out, everyone's happy.
OP: I've got some CSS classes that are formatted as italic. If there's emphasized or italicized text inside those classes in a book, there's no visible difference from the rest of the text. After getting tired of trying to wrap such text with font-style: normal spans, I decided to try a nesting selector (&) in those classes to automatically apply the normal font-style when it runs into <i> and <em>. Here's an example:

Code:
div.chapquote {
	/* Chapter Quote (quote at top of chapters) Styling */
	display: block;
	font-style:	italic;
	margin-left:	1.5em;
	margin-right:	1.5em;
	padding-left: 1.5em;
	padding-right:	1.5em;
	text-align: justify;
  & em	{
    font-style: normal;
  }
  & i	{
    font-style: normal;
  }
}
That css seems to work just fine. The Calibre Editor's Check Book function has no problem with it. But, EpubCheck doesn't like it at all. It spits out:
Code:
ERROR CSS-008: An error occurred while parsing the CSS: Token "&" not allowed here. expecting a property name.
I don't know what's wrong. Any suggestions?

Last edited by enuddleyarbl; Yesterday at 03:19 PM.
enuddleyarbl is offline   Reply With Quote
Old Yesterday, 03:26 PM   #2
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 85,615
Karma: 154365185
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
& won't work in most cases. So don't use it. Most programs that handle ePub won't work with &.
JSWolf is offline   Reply With Quote
Old Yesterday, 03:48 PM   #3
enuddleyarbl
Guru
enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.
 
enuddleyarbl's Avatar
 
Posts: 911
Karma: 2111023
Join Date: Sep 2013
Device: Kobo Sage
How should I go about getting <i> and <em> tagged text to be recognizable (in my case, font-style: normal) in text that is styled with an italicized CSS?

BTW: it turns out that if I remove the & in those styles, EpubCheck is happy with it being gone, but then complains about the {} bracketing the font-style:normal stuff.
enuddleyarbl is offline   Reply With Quote
Old Yesterday, 03:57 PM   #4
enuddleyarbl
Guru
enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.
 
enuddleyarbl's Avatar
 
Posts: 911
Karma: 2111023
Join Date: Sep 2013
Device: Kobo Sage
I guess I could try pulling out the stuff the nesting selector was supposed to shortcut and adding it myself. In the above example, I think I'd add the following:
Code:
div.chapquote em	{
    font-style: normal;
  }
div.chapquote i	{
    font-style: normal;
  }
enuddleyarbl is offline   Reply With Quote
Old Yesterday, 04:25 PM   #5
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 85,615
Karma: 154365185
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by enuddleyarbl View Post
How should I go about getting <i> and <em> tagged text to be recognizable (in my case, font-style: normal) in text that is styled with an italicized CSS?

BTW: it turns out that if I remove the & in those styles, EpubCheck is happy with it being gone, but then complains about the {} bracketing the font-style:normal stuff.
That's very poor coding. You should not use <i> or <em> to mean a normal font style.

create a class such as...
Code:
.normal {
  font-style: normal;
}
Use the following regex (for a paragraph) to search (in the calibre editor). Replace italic with the name of the class you want.
Code:
(?s)(<p\b[^>]*class="[^"]*\bitalic\b[^"]*"[^>]*>(?:(?!</p>).)*?)<(i|em)\b[^>]*>(.*?)</\2>
Use the following regex search for a <div>. Also replace italic with your class name.
Code:
(?s)(<div\b[^>]*class=["'][^"']*\bitalic\b[^"']*["'][^>]*>(?:(?!</div>).)*?)<(i|em)\b[^>]*>(.*?)</\2>
This is the replace code for <p> or <div>.
Code:
\1<span class="normal">\3</span>

Last edited by JSWolf; Yesterday at 04:40 PM.
JSWolf is offline   Reply With Quote
Old Yesterday, 04:37 PM   #6
enuddleyarbl
Guru
enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.
 
enuddleyarbl's Avatar
 
Posts: 911
Karma: 2111023
Join Date: Sep 2013
Device: Kobo Sage
I already have a "normal" class. I was initially replacing those <i> and <em> blocks with that. I don't want to do that (manually or with a regex). In those blocks of text that I've formatted with italicized CSS, I want any existing <i> and <em> "spans" to automatically display as "normal". I have a dozen or so classes that are italicized. I was trying to find a reasonable way to modify the CSS to do that.

Replacing all the nesting selectors in those classes with the separately broken out classes works, though it's ugly. But, now Calibre is complaining that those new classes near the bottom of my CSS are problematic because of "no-descending-specificity:"

https://stylelint.io/user-guide/rule...g-specificity/
enuddleyarbl is offline   Reply With Quote
Old Yesterday, 04:42 PM   #7
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 85,615
Karma: 154365185
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
This should be your CSS.
Code:
div.chapquote {
/* Chapter Quote (quote at top of chapters) Styling */
  display: block;
  font-style: italic;
  margin-left: 1.5em;
  margin-right: 1.5em;
}
.normal {
  font-style: normal;
}
JSWolf is offline   Reply With Quote
Old Yesterday, 04:47 PM   #8
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 85,615
Karma: 154365185
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by enuddleyarbl View Post
I already have a "normal" class. I was initially replacing those <i> and <em> blocks with that. I don't want to do that (manually or with a regex). In those blocks of text that I've formatted with italicized CSS, I want any existing <i> and <em> "spans" to automatically display as "normal". I have a dozen or so classes that are italicized. I was trying to find a reasonable way to modify the CSS to do that.

Replacing all the nesting selectors in those classes with the separately broken out classes works, though it's ugly. But, now Calibre is complaining that those new classes near the bottom of my CSS are problematic because of "no-descending-specificity:"

https://stylelint.io/user-guide/rule...g-specificity/
You have to remember that this is ePub, not a full blown web browser. While calibre will handle more then your average ePub reading software because of Qt 6 (via PyQt6). So the regex I supplied is the best way to do this. What you are doing in calibre will not work as an ePub on your Kobo. RMSDK does not support these sorts of things.
JSWolf is offline   Reply With Quote
Old Yesterday, 05:39 PM   #9
enuddleyarbl
Guru
enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.
 
enuddleyarbl's Avatar
 
Posts: 911
Karma: 2111023
Join Date: Sep 2013
Device: Kobo Sage
Well, I just went and brute-forced my CSS. For the class I noted, above, it now looks like this:
Code:
div.chapquote {
	/* Chapter Quote (quote at top of chapters) Styling */
	display: block;
	font-style:	italic;
	margin-left:	1.5em;
	margin-right:	1.5em;
	padding-left: 1.5em;
	padding-right:	1.5em;
	text-align: justify;
}
div.chapquote em	{
	font-style:	normal;
}
div.chapquote i	{
	font-style:	normal;
}
I added those em and i classes to every class I had that used
Code:
font-style: italic
. Then, when the Calibre Editor's Check Book function complained about specificity for some very specific classes near the bottom of my CSS stylesheet, I just dragged those classes up near the top in their own "because Calibre told me so" section.

Not exactly elegant, but it works.

I've also opened an issue with EpubCheck:

https://github.com/w3c/epubcheck/issues/1765

They could very well come back and say Nesting Selectors don't work in Epubs, so that's why it errors on the & (though a more meaningful error message would be nice).
enuddleyarbl is offline   Reply With Quote
Old Yesterday, 06:02 PM   #10
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,520
Karma: 21099999
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
Or you can use a very simple technique that works everywhere:

Code:
em em {font-style:normal}
i i   {font-style:normal}
.NameOfYourItalicStyle em, .NameOfYourItalicStyle i {font-style:normal}
This technique can be used because the css is looking for an em inside of an em, or an i inside of an i, or either inside whatever class you use that defines font-style:italic. It is a way to emphasize something by making it different from the surrounding letters/words. Most people would default em to italics but it certainly doesn’t need to… the em could denote a color, or a font size, or a text decoration… anything to emphasize the word.

Eg.
Code:
<p class="mentalspeak">I am emphasizing <em>this</em> word 
within a phrase that is italicized.</p>

CSS:
.mentalspeak {font-style:italic}
.mentalspeak em {font-style:normal; color:red; text-decoration:underline}

RESULT:
I am emphasizing this word within a phrase that is italicized.
That provides a very clean, easy to read (in code view), and simple to code.
Turtle91 is offline   Reply With Quote
Old Yesterday, 06:57 PM   #11
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 10,215
Karma: 7640000
Join Date: Nov 2009
Device: many
DeNesting the css is probably for the best if you want your epub to work on a large number of readers. The support for nesting css is quite new and therefore it is not supported by many e-readers. Plus there are many problems using nested css especially when the nesting gets more than 2 levels deep.

It is for this reason, Sigil has a built-in denesting code in recent versions. Enter it in nested form then use css reformat to unnest it for more general consumption. Ease of entry for you. Nicely denested normal css code that will work almost everywhere for e-readers.
KevinH is offline   Reply With Quote
Old Yesterday, 09:30 PM   #12
enuddleyarbl
Guru
enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.
 
enuddleyarbl's Avatar
 
Posts: 911
Karma: 2111023
Join Date: Sep 2013
Device: Kobo Sage
Quote:
Originally Posted by Turtle91 View Post
Or you can use a very simple technique that works everywhere:

Code:
em em {font-style:normal}
i i   {font-style:normal}
.NameOfYourItalicStyle em, .NameOfYourItalicStyle i {font-style:normal}
...
Aargh! I thought I had the i i or em em code in my stylesheet. But, it wasn't working. I just took another look at it and instead of the descendant combinator you have, I have a child combinator (>). Yours applies to all descendants whereas mine applies to only direct children.

Ugh. In general, my italics are being applied at the div.class level. But, the emphasis is happening at the div.class p or lower level. So, the child combinator wasn't matching. I had assumed it was failing because it was looking for the actual <i> or <em> tags instead of the
Code:
font-style: italic
bit.

I'll have to test that just to make sure. Then I'm going to rest for a while before I redo my standard stylesheet again. Ugh.

Thanks, though.
enuddleyarbl is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS selectors BobC ePub 6 02-07-2019 06:11 AM
EPUB and HTML Selectors Rand Brittain ePub 2 03-06-2015 01:44 AM
HTML Tags and CSS Selectors Doctor T Kindle Formats 3 10-26-2014 12:50 AM
Div Selectors vs Paragraph Classes -- Robustness? GrannyGrump ePub 14 10-08-2013 09:49 AM
ADE support for attribute-value based selectors? dmapr ePub 0 08-06-2010 06:57 PM


All times are GMT -4. The time now is 01:51 AM.


MobileRead.com is a privately owned, operated and funded community.