Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 09-26-2015, 05:51 PM   #1
ignaz wrangel
Member
ignaz wrangel began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Sep 2015
Device: kindle 4g
CSS question: breaks and indents

Hi everybody I'm a css and epub beginner.

My source consists of many continuous blocks of text whose paragraphs are marked by an indent. I wanted the first paragraph each block to be un-indented so I added some css
Code:
p {
  margin: 0; }
p + p {
  text-indent: 1em; }
But the source also includes paragraphs separated by line breaks, and this is where I had trouble. Flightdeck says that <br /> is not allowed in epubs, and sigil wanted to clean up the html by wrapping each one in <p> tags. Of course this meant that every first paragraph in a block was now preceeded by a <p> and got indented.

I found a solution already which is to wrap all the break tags in div tags, but my question is: is this a reasonable solution? What is the normal approach?

Should all of these blocks be contained by tags?

Should I add a class to every first paragraph of every block that follows another?

Thanks for any tips
ignaz wrangel is offline   Reply With Quote
Old 09-26-2015, 06:50 PM   #2
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,347
Karma: 20171571
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
Adding all those tags will work but it is not considered "in good form"... and it is a whole heck of a lot of work...lol

Flightcheck is telling you it doesn't like <br /> all by itself...it needs to be wrapped in a different tag <p><br /></p> or <div><br /></div>...but there is a much better way to organize your paragraphs:

Let Sigil wrap each paragraph in a paragraph tag - that's what they are for. Don't use <br /> tags to give spaces between paragraphs.

Then you can style the paragraphs however you want using a CSS stylesheet. For example:

Code:
<p class="first">This is the first paragraph. It has a zero indent on the first line.</p>
<p>This is the second paragraph. It has a 1.2em indent by default.</p>
<p>This is the third paragraph. It has a 1.2em indent by default.</p>
<p>This is the fourth paragraph. It has a 1.2em indent by default.</p>


CSS:
p       {text-indent:1.2em}
p.first {text-indent:0}

You can further style your paragraphs with extra space and no indent (eg a scene break in a chapter) by giving it it's own class:

Code:
<p class="SecBrk">This is the first paragraph after a scene break. It has a zero indent on the first line and extra space before the paragraph.</p>
<p>This is the second paragraph. It has a 1.2em indent by default.</p>

CSS:
p.SecBrk {text-indent:0; margin-top:2em}


The final product would look something like this:

Code:
<p class="first">This is the first paragraph. It has a zero indent on the first line.</p>
<p>This is the second paragraph. It has a 1.2em indent by default.</p>
<p>This is the third paragraph. It has a 1.2em indent by default.</p>
<p>This is the fourth paragraph. It has a 1.2em indent by default.</p>
<p class="SecBrk">This is the first paragraph after a scene break. It has a zero indent on the first line and extra space before the paragraph.</p>
<p>This is the second paragraph. It has a 1.2em indent by default.</p>
<p>This is the third paragraph. It has a 1.2em indent by default.</p>
<p>This is the fourth paragraph. It has a 1.2em indent by default.</p>


CSS:
p        {text-indent:1.2em}
p.first  {text-indent:0}
p.SecBrk {text-indent:0; margin-top:2em}
In my opinion you should define the default paragraph the way you want the vast majority of your paragraphs to look, and save the specific classes for specific paragraphs that look different. That means a lot less work for you when you are creating the epub, and a lot less work for the reader/app when it is trying to display your book (thus it is a smoother/faster experience for the end user.)
Cheers!

Last edited by Turtle91; 09-26-2015 at 06:57 PM.
Turtle91 is offline   Reply With Quote
Advert
Old 09-26-2015, 07:18 PM   #3
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 31,047
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by ignaz wrangel View Post
Hi everybody I'm a css and epub beginner.

My source consists of many continuous blocks of text whose paragraphs are marked by an indent. I wanted the first paragraph each block to be un-indented so I added some css
Code:
p {
  margin: 0; }
p + p {
  text-indent: 1em; }
But the source also includes paragraphs separated by line breaks, and this is where I had trouble. Flightdeck says that <br /> is not allowed in epubs, and sigil wanted to clean up the html by wrapping each one in <p> tags. Of course this meant that every first paragraph in a block was now preceeded by a <p> and got indented.

I found a solution already which is to wrap all the break tags in div tags, but my question is: is this a reasonable solution? What is the normal approach?

Should all of these blocks be contained by tags?

Should I add a class to every first paragraph of every block that follows another?

Thanks for any tips
Flightcrew is simply reminding you No Nekid Br allowed

You could include it inside the last </p
put it in a <div pair to prevent tripping your p+p, that might be unnecessary as the div needs to just contain a nbsp for a 1 liner break
or turtle91 style it with its own class which also allows for full
CSS control . < I like this one. I am not trying to save a few dozen bytes
theducks is offline   Reply With Quote
Old 09-26-2015, 08:16 PM   #4
ignaz wrangel
Member
ignaz wrangel began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Sep 2015
Device: kindle 4g
OK thanks, I think that’s cleared it up for me.

The p.scenebreak approach is best.

theduck: I see that nbsp inside <div> before </p> works as you say, That makes it a little neater.

Incidentally I’m gonna stick with the <div> approach for this project. I’m correcting paragraph structure in Sigil’s book mode. Ctrl+return splits the paragraph and inserts <p><br /></p> - and I can find/replace or regex this into shape when I’m done. I would use the other approach if there was a customisable keystroke to modify the <p> tag like the header keystrokes do. Clips won’t work quite like this unless I’m mistaken.
ignaz wrangel is offline   Reply With Quote
Old 09-26-2015, 08:19 PM   #5
ignaz wrangel
Member
ignaz wrangel began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Sep 2015
Device: kindle 4g
in fact I could even use regex to modify the <p> that follows the <p><br /></p>. Best of both worlds!
ignaz wrangel is offline   Reply With Quote
Advert
Old 09-26-2015, 09:00 PM   #6
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: 79,740
Karma: 145864619
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 ignaz wrangel View Post
in fact I could even use regex to modify the <p> that follows the <p><br /></p>. Best of both worlds!
Nope. The new Kindle rendering engine does not line that. Use a class with a margin be it top or bottom to get the space/
JSWolf is offline   Reply With Quote
Old 09-26-2015, 09:48 PM   #7
ignaz wrangel
Member
ignaz wrangel began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Sep 2015
Device: kindle 4g
What I have in mind is to use the break inserted by sigil (<p><br /></p>) as a marker to locate the paragraphs that follow it and add a class to their <p> tag, the marker is then deleted. Is this what you mean?

something like

Code:
<p><br /></p>[^<]*<p\b[^>]*>

replace with:

<p class=“scenebreak”>
ignaz wrangel is offline   Reply With Quote
Old 09-26-2015, 09:56 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: 79,740
Karma: 145864619
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 ignaz wrangel View Post
What I have in mind is to use the break inserted by sigil (<p><br /></p>) as a marker to locate the paragraphs that follow it and add a class to their <p> tag, the marker is then deleted. Is this what you mean?

something like

Code:
<p><br /></p>[^<]*<p\b[^>]*>

replace with:

<p class=“scenebreak”>
Sort of.

If you have...

<p><br /></p>
<p>Some paragraph text.</p>

then it would be best to be...

<p class="scenebreak">Some paragraph text.</p>

That would make the code even neater and would mean that you can also include a text indent of 0.
JSWolf is offline   Reply With Quote
Old 09-26-2015, 10:16 PM   #9
jhowell
Grand Sorcerer
jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.
 
jhowell's Avatar
 
Posts: 7,069
Karma: 91577715
Join Date: Nov 2011
Location: Charlottesville, VA
Device: Kindles
Quote:
Originally Posted by ignaz wrangel View Post
in fact I could even use regex to modify the <p> that follows the <p><br /></p>. Best of both worlds!
Quote:
Originally Posted by JSWolf View Post
Nope. The new Kindle rendering engine does not line that. Use a class with a margin be it top or bottom to get the space/
Sorry for the off topic comment here, but I don't think this is true. Kindle enhanced typesetting ignores a paragraph containing only a non-breaking space. I haven't heard of any issues with using a br tag.
jhowell is offline   Reply With Quote
Old 09-26-2015, 10:20 PM   #10
ignaz wrangel
Member
ignaz wrangel began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Sep 2015
Device: kindle 4g
Quote:
Originally Posted by JSWolf View Post
Sort of.

If you have...

<p><br /></p>
<p>Some paragraph text.</p>

then it would be best to be...

<p class="scenebreak">Some paragraph text.</p>

That would make the code even neater and would mean that you can also include a text indent of 0.
the regex I posted produces that, it selects the marker and the following opening <p>, and replaces the lot with <p class="scenebreak">, the rest just remains in place ("some paragraph text</p>")
ignaz wrangel is offline   Reply With Quote
Old 09-26-2015, 11:05 PM   #11
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: 79,740
Karma: 145864619
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 jhowell View Post
Sorry for the off topic comment here, but I don't think this is true. Kindle enhanced typesetting ignores a paragraph containing only a non-breaking space. I haven't heard of any issues with using a br tag.
My mistake. But it is bad form and poor code to use a <br/> between paragraphs or even as a section break.
JSWolf is offline   Reply With Quote
Old 09-26-2015, 11:09 PM   #12
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: 79,740
Karma: 145864619
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 ignaz wrangel View Post
the regex I posted produces that, it selects the marker and the following opening <p>, and replaces the lot with <p class="scenebreak">, the rest just remains in place ("some paragraph text</p>")
You do have a bug in your regex.

<p><br /></p>[^<]*<p\b[^>]*> <---incorrect

<p><br /></p>[^<]*<p> <---correct

You do not want to replace the following <p> willy nilly if hit has a class. You want to only replace the br line and the p only if the <p> is just a plain <p>. If it has a class and you want to replace the p and the class, run the regex again specifying the specific class. Then you can see if you have any more br lines left and how you want to deal with them.
JSWolf is offline   Reply With Quote
Old 09-27-2015, 01:11 AM   #13
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,347
Karma: 20171571
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
Quote:
Originally Posted by ignaz wrangel View Post
What I have in mind is to use the break inserted by sigil (<p><br /></p>) as a marker to locate the paragraphs that follow it and add a class to their <p> tag, the marker is then deleted. Is this what you mean?

something like

Code:
<p><br /></p>[^<]*<p\b[^>]*>

replace with:

<p class=“scenebreak”>

Wow! For a CSS/ePub beginner your reg-fu is strong!
Turtle91 is offline   Reply With Quote
Old 09-27-2015, 05:27 AM   #14
ignaz wrangel
Member
ignaz wrangel began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Sep 2015
Device: kindle 4g
JSWolf: Thanks, you're right. I should run a search for <p[^>] first before I do anything anyway.

Turtle91: Thanks. I've already left a swathe of destruction behind me in my short career.
ignaz wrangel is offline   Reply With Quote
Old 10-03-2015, 05:41 PM   #15
Hitch
Bookmaker & Cat Slave
Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.
 
Hitch's Avatar
 
Posts: 11,503
Karma: 158448243
Join Date: Apr 2010
Location: Phoenix, AZ
Device: K2, iPad, KFire, PPW, Voyage, NookColor. 2 Droid, Oasis, Boox Note2
Quote:
Originally Posted by ignaz wrangel View Post
JSWolf: Thanks, you're right. I should run a search for <p[^>] first before I do anything anyway.

Turtle91: Thanks. I've already left a swathe of destruction behind me in my short career.
If you're not destroying stuff while learning regex-fu, you're not trying to learn hard enough. ;-) I'm bloody NOTORIOUS for it.

Hitch
Hitch is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ADE breaks CSS --> CSS Validation: Parse Error / Value Error dasboeh ePub 4 12-10-2012 03:25 AM
PML to EPUB - indents and scene breaks snarkophilus Conversion 1 12-26-2011 01:02 PM
Indents not working + CSS styles missing virtual_ink ePub 1 07-04-2011 07:41 AM
CSS for line breaks after dashes? JaneFancher Sigil 4 04-05-2010 12:18 PM
convert to lrf : paragraph indents, line breaks karo02 Calibre 4 01-27-2009 09:19 AM


All times are GMT -4. The time now is 05:54 AM.


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