11-22-2022, 06:20 PM | #1 |
Junior Member
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! |
11-22-2022, 09:20 PM | #2 |
Well trained by Cats
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;} |
11-24-2022, 09:44 AM | #3 |
Junior Member
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 :
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 |
11-24-2022, 12:19 PM | #4 |
Well trained by Cats
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) |
11-24-2022, 12:23 PM | #5 |
Not Quite Dead
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. |
11-24-2022, 01:40 PM | #6 |
Addict
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... |
11-24-2022, 02:05 PM | #7 | |
Running with scissors
Posts: 1,552
Karma: 14325282
Join Date: Nov 2019
Device: none
|
Quote:
|
|
11-24-2022, 02:19 PM | #8 |
Resident Curmudgeon
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
|
Why do you want to use some pretty poor code? @theducks suggestion to use classes is what you really should be doing.
|
11-25-2022, 01:26 AM | #9 | ||||
Wizard
Posts: 2,297
Karma: 12126329
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
Quote:
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:
Instead, you'd:
This will carry over all your paragraphs. Quote:
Do this in a word processor. (Microsoft Word, LibreOffice, etc.) You could:
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:
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> Code:
<p>This is paragraph 1.</p> <p>This is paragraph 2.</p> <p>This is paragraph 3.</p> Quote:
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; } Code:
p { margin-top: 1em; margin-bottom: 0; text-align: justify; text-indent: 0; } 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. |
||||
11-25-2022, 08:14 AM | #10 |
Junior Member
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-
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. |
11-25-2022, 11:02 AM | #11 | |
Not Quite Dead
Posts: 194
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
Quote:
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. |
|
Tags |
calibre, editing ebook in calibre |
|
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 |