Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Editor

Notices

Reply
 
Thread Tools Search this Thread
Old 11-22-2022, 06:20 PM   #1
MgHar
Junior Member
MgHar began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Nov 2022
Device: Kobo Forma
Auto-add <br/> tag in every blank line

Hi, after pasting a text in Calibre's editor, I would like to automatically add a <br/> tag to every blank line within a <p> tag

I do not wish to use the </pre> tag.

Thanks for your help!
MgHar is offline   Reply With Quote
Old 11-22-2022, 09:20 PM   #2
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: 29,997
Karma: 57259778
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
We are not using Typewriters

What is the purpose ?
If you want line spacing, add a margin-top:1em; to the P class (or make a new one)

<p class="first"> This is a line with a blank line before</p>

p.first {display:block ; margin-top:1em;}
theducks is offline   Reply With Quote
Old 11-24-2022, 09:44 AM   #3
MgHar
Junior Member
MgHar began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Nov 2022
Device: Kobo Forma
Auto-add <br/> tag in every blank line (follow up)

Thanks for your reply theducks, I really appreciate you taking time to help with this. I tried adding a margin-top:1em; to the P class as suggested.

First let me explain what I'm trying to achieve (I realize that my initial post was not clear):

In Calibre's Editor :
  1. I create a blank ePub book
  2. Then I paste text within a <p></p> tag (the text might be 50 to 100 pages long, divided in hundreds of paragraphs)

The immediate result (visible in the preview pane of the editor) is that the text loses its paragraphs (which is normal with a p tag) BUT the text will dynamically auto-adjust the wrapping, regardless of the e-reader settings (that's an essential upside) (please see Capture 1 file attached).

Notice that when I pasted the text, empty lines appear between each paragraph (lines 14, 16 and 18)

The only way that I found to keep the "auto-wrap" WITHIN each paragraph AND achieve paragraph separation, is to add a double <br/> tag to each blank line.

In Capture 2 you'll see that I've added "<br/><br/>" to lines 14, 16 and 18. The result is visible in the preview pane. The paragraphs are now separated AND if I adjust the preview pane width, the wrapping will auto-adjust perfectly, and the paragraphs will remain separated. That's the result I'm looking for.

If my texts had only 10-20 paragraphs, I would add the <br/> tags manually. BUT with hundreds of paragraphs, the process juste becomes too much.

So there you have it, this is the purpose of my posting.

As mentioned at the beginning of this post I tried adding a margin-top:1em; to the P class as suggested. If you take a look at Capture 3, the text remains a big block with no paragraph separation.

My idea was to find a way to "auto-add" the "<br/><br/>" tags to every empty line. I'm a newbie to html, so perhaps there is a better way to achieve the same result.

Thanks for your help

Click image for larger version

Name:	Capture 1.png
Views:	99
Size:	537.2 KB
ID:	197977

Click image for larger version

Name:	Capture 2.png
Views:	127
Size:	545.1 KB
ID:	197978

Click image for larger version

Name:	Capture 3.png
Views:	83
Size:	557.2 KB
ID:	197979
MgHar is offline   Reply With Quote
Old 11-24-2022, 12:19 PM   #4
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: 29,997
Karma: 57259778
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Every one of those gaps could be </p> <p> instead.

Or you could style those further (assumes p has a 0 indent)
</p> <p class="indented">

the Stylesheet would have
.indented {text-indent: 1.5em;}

If this SOURCE was a complete TXT file, calibre can convert that to be closer to what you want initially.

KEEP a safe copy before you start.
Simply Select the Gap (from end of the line to the start of the next Paragraph)
ctrl-F
Use the above as the replace.
Step thru find, replace-find next to see if this is good (abort the edit if not)
theducks is offline   Reply With Quote
Old 11-24-2022, 12:23 PM   #5
Brett Merkey
Not Quite Dead
Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.
 
Posts: 194
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
Try this:

Paste your text raw into a .txt file. Import that into Calibre and convert to epub. Calibre adds classed P tags and that might work for you. If you want plain P tags, empty out the default style sheet and then use the "clean styles" tool.
Brett Merkey is offline   Reply With Quote
Old 11-24-2022, 01:40 PM   #6
retiredbiker
Addict
retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.
 
retiredbiker's Avatar
 
Posts: 390
Karma: 1638210
Join Date: May 2013
Location: Ontario, Canada
Device: Kindle KB, Oasis, Pop_Os!, Jutoh, Kobo Forma
You might try a regex search & replace.

Search for \n\n
Replace with <br/><br/> (or a <p -something like theducks suggests)

Go one-at-a-time until you are sure it behaves with your long text...
retiredbiker is offline   Reply With Quote
Old 11-24-2022, 02:05 PM   #7
hobnail
Running with scissors
hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.
 
Posts: 1,552
Karma: 14325282
Join Date: Nov 2019
Device: none
Quote:
Originally Posted by MgHar View Post
In Capture 2 you'll see that I've added "<br/><br/>" to lines 14, 16 and 18. The result is visible in the preview pane. The paragraphs are now separated AND if I adjust the preview pane width, the wrapping will auto-adjust perfectly, and the paragraphs will remain separated. That's the result I'm looking for.

Attachment 197978
Just in case the other explanations didn't help, here's mine: In Capture 2 replace the <br/><br/> with </p><p>. The </p> ends the <p> at the top and then the <p> starts a new paragraph, giving you the same visual effect, after you add the class and margin-top CSS as per the suggestion from theducks. You can do a search and replace for a blank line.
hobnail is offline   Reply With Quote
Old 11-24-2022, 02:19 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: 74,701
Karma: 130140792
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 MgHar View Post
Hi, after pasting a text in Calibre's editor, I would like to automatically add a <br/> tag to every blank line within a <p> tag

I do not wish to use the </pre> tag.

Thanks for your help!
Why do you want to use some pretty poor code? @theducks suggestion to use classes is what you really should be doing.
JSWolf is offline   Reply With Quote
Old 11-25-2022, 01:26 AM   #9
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 2,297
Karma: 12126329
Join Date: Jul 2012
Device: Kobo Forma, Nook
Quote:
Originally Posted by MgHar View Post
Then I paste text within a <p></p> tag (the text might be 50 to 100 pages long, divided in hundreds of paragraphs)
Are you trying to copy/paste an entire book?

This would be much better if you CONVERTED between formats instead.

- - -

For example, if you have a DOCX of your book:

It wouldn't be smart to:
  • Copy your document + try to paste into Calibre...

Instead, you'd:
  • Use Calibre to convert DOCX->EPUB.

This will carry over all your paragraphs.

Quote:
Originally Posted by MgHar View Post
If my texts had only 10-20 paragraphs, I would add the <br/> tags manually. BUT with hundreds of paragraphs, the process juste becomes too much.
If HTML+CSS seems a little too complicated for you, you may also want to:

Do this in a word processor. (Microsoft Word, LibreOffice, etc.)

You could:
  • paste your text in there
  • do some cleanup
  • then convert that document into EPUB via Calibre.

Watch these 2 amazing videos:

and within <30 minutes, you'll learn how to create very clean documents (which can then be turned into very clean ebooks!).

Quote:
Originally Posted by MgHar View Post
The immediate result (visible in the preview pane of the editor) is that the text loses its paragraphs (which is normal with a p tag) BUT the text will dynamically auto-adjust the wrapping, regardless of the e-reader settings (that's an essential upside) (please see Capture 1 file attached).
Like the others have explained... in HTML:
  • <p> stands for paragraphs.

You do not hit "ENTER ENTER ENTER" to "create empty lines between paragraphs"...

You actually mark each paragraph as paragraphs!

BAD:

Code:
<p>This is paragraph 1.<br/>
<br/>
This is paragraph 2.<br/>
<br/>
This is paragraph 3.</p>
GOOD:

Code:
<p>This is paragraph 1.</p>

<p>This is paragraph 2.</p>

<p>This is paragraph 3.</p>
Quote:
Originally Posted by MgHar View Post
In Capture 2 you'll see that I've added "<br/><br/>" to lines 14, 16 and 18. The result is visible in the preview pane. The paragraphs are now separated AND if I adjust the preview pane width, the wrapping will auto-adjust perfectly, and the paragraphs will remain separated. That's the result I'm looking for.
I think you have to go completely back to the basics.

Do you know the basics of HTML? Do you know (at least a little) CSS?

With CSS, you can adjust the look of your entire book with a few lines.

Do you want your paragraphs to look like a typical book?

Code:
p {
	margin-top: 0;
	margin-bottom: 0;
	text-align: justify;
	text-indent: 2em;
}
Do you want your paragraphs to have a gap between them all?

Code:
p {
	margin-top: 1em;
	margin-bottom: 0;
	text-align: justify;
	text-indent: 0;
}
That's the power of marking your "paragraphs as paragraphs" + using CSS.

The 1st one says: "Hey! Give me an indent + don't put a margin on top!"

The 2nd one says: "Hey! Put a margin on top + don't give me an indent!"

Last edited by Tex2002ans; 11-25-2022 at 01:31 AM.
Tex2002ans is offline   Reply With Quote
Old 11-25-2022, 08:14 AM   #10
MgHar
Junior Member
MgHar began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Nov 2022
Device: Kobo Forma
Auto-add <br/> tag in every blank line

Thank you all for your very helpful replies!

I learned a lot in the last 48 hours just by experimenting with the solutions you guys provided.

My field of work is not coding as you surely figured out, but I'm a quick learner. With very minimal knowledge I already managed to create a few ePub bike trip itineraries with imbedded maps and text, providing me with an 8" screen strapped to my handlebar that uses almost no power and works in full sunlight (e-ink screens are just amazing).

Regarding my post and your replies, I will up my html/CSS game in a more structured manner (quick online course) and definitely watch the videos recommended by Tex2002an. Thanks to theducks and Brett Merkey for providing two avenues ("p class" and "text file import") that I tested over and over and allowed me to gain valuable practice and understanding of some fundamentals.

For now, and for my particular situation, here's what I ended up doing:

Right-
  1. click on the ".txt" file that contains my text and select "open with Calibre"
  2. In Calibre, convert the book to ePub
  3. Open the book in Calibre's Editor
  4. Adjust title and other metadata to my liking
  5. Upload
to my Kobo Forma

I realize now that Calibre's conversion tool is a pretty powerful piece of software.

Everyone who replied in this thread contributed in helping me advance my understanding of HTML and of Calibre's more advanced functionalities.

Thank you all.
MgHar is offline   Reply With Quote
Old 11-25-2022, 11:02 AM   #11
Brett Merkey
Not Quite Dead
Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.
 
Posts: 194
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
Quote:
click on the ".txt" file that contains my text and select "open with Calibre"
In Calibre, convert the book to ePub
Open the book in Calibre's Editor
<<I realize now that Calibre's conversion tool is a pretty powerful piece of software.>>

Very true. I spent many unnecessary hours manipulating raw text with a text editor and regular expressions (not fun!) before learning that those 3 steps above would save a ton of aggravation.
Brett Merkey is offline   Reply With Quote
Reply

Tags
calibre, editing ebook in calibre


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I make calibre auto tag books i add based on their path/folder name? polo2005 Library Management 7 04-20-2020 02:03 AM
Vanishing auto add books during import, books left behind in auto add folder jataadroid Library Management 9 01-14-2018 11:43 PM
Add blank line between two lines coolpixel Sigil 1 11-08-2014 02:13 PM
How to prevent calibre add a blank line at every <p> Nick_1964 Conversion 12 11-26-2013 05:44 AM
Why does the [code] tag add an empty line at the end? DSpider Feedback 3 06-01-2012 07:34 AM


All times are GMT -4. The time now is 07:02 AM.


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