Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 11-27-2025, 10:54 AM   #1
LenaWolf
Member
LenaWolf began at the beginning.
 
LenaWolf's Avatar
 
Posts: 23
Karma: 10
Join Date: Oct 2025
Device: Sony PRS-T3, Kobo Libra Colour
Transform HTML - Insert HTML after tag - does not insert immediately after tag

Hi,

I want to insert a short HTML snippet after every <br/> tag, but I want it to be immediately after the tag. However, when I specify the rule "Insert HTML after tag", the snippet is inserted before the next tag instead of immediately after <br/>. How can I fix it, please?

Now in more detail. I have the following HTML:

<p class="P-P500 c_odt5">
<span class="S-Drop_20_Caps">I </span>never... blablabla more text. <br/>
"I told you - blablabla more text.</p>

I would like to have the following snippet inserted immediately after <br/>:

<span class="drop_caps_tab"/>

So I click Convert books -> Look and Feel -> Transform HTML, and there I add a new rule: if tag is br, insert HTML after tag, and I type in the above HTML for <span>. Then I run the conversion.

I have several places in the document where this rule applies, and the results vary quite a bit, but my <span> code is never inserted immediately after <br/> but instead it is inserted immediately before the next tag or before the closing of the wrapper tag, which is not what I want. Here are some examples of what I get as a result:

<p class="p-body_20_text_20_first_20_paragraph">
<span class="s-drop_20_caps">I </span>never... blablabla <br class="calibre2"/>
"I told you...blablabla <span class="drop_caps_tab"></span></p>

(In this case my <span> was inserted before the closing tag </p>.)

<p class="p-body_20_text_20_first_20_paragraph">
<span class="s-drop_20_caps">F</span>inally!" Agatha...text. <br class="calibre2"/>
"<span class="drop_caps_tab"></span><span class="calibre">I was</span>n't worried,"...blablabla</p>

(In this case, my <span> was inserted before the next <span> element that was in the code already.)

My question is then: how to make my snippet be inserted immediately after <br/>? I want the following result:

<br/><span class="drop_caps_tab"/>

I don't want anything in between, and certainly none of my text. I already tried all other options in the rules but still cannot get it to work. I can get tags inserted before <br/> but not after.
LenaWolf is offline   Reply With Quote
Old 11-29-2025, 04:08 AM   #2
Ghostcat
Connoisseur
Ghostcat ought to be getting tired of karma fortunes by now.Ghostcat ought to be getting tired of karma fortunes by now.Ghostcat ought to be getting tired of karma fortunes by now.Ghostcat ought to be getting tired of karma fortunes by now.Ghostcat ought to be getting tired of karma fortunes by now.Ghostcat ought to be getting tired of karma fortunes by now.Ghostcat ought to be getting tired of karma fortunes by now.Ghostcat ought to be getting tired of karma fortunes by now.Ghostcat ought to be getting tired of karma fortunes by now.Ghostcat ought to be getting tired of karma fortunes by now.Ghostcat ought to be getting tired of karma fortunes by now.
 
Posts: 68
Karma: 582370
Join Date: Apr 2023
Device: Kobo Clara 2E, Pocketbook Inkpad 4
Personally, I would not use Transfer HTML for this; I would use Search and Replace.

Search for <br/> and replace with <br/><span class="drop_caps_tab"/>.

That said you appear to be missing the closing </span> tag. This would make the search slightly more complicated as you would need account for the closing tag in your search. So for the example given, I suggest:

Search for <br/>\n("?[A-Z]) and replace with <br/><span class="drop_caps_tab"/>\n\1</span>.
Ghostcat is offline   Reply With Quote
Old 11-29-2025, 05:41 AM   #3
Karellen
Wizard
Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.Karellen ought to be getting tired of karma fortunes by now.
 
Karellen's Avatar
 
Posts: 1,703
Karma: 9500498
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
Yes, I also would use a Search and Replace in the Editor, rather than fiddling with a conversion rule.
Karellen is offline   Reply With Quote
Old 11-29-2025, 07:54 PM   #4
LenaWolf
Member
LenaWolf began at the beginning.
 
LenaWolf's Avatar
 
Posts: 23
Karma: 10
Join Date: Oct 2025
Device: Sony PRS-T3, Kobo Libra Colour
Quote:
Originally Posted by Ghostcat View Post
Personally, I would not use Transfer HTML for this; I would use Search and Replace.

Search for <br/> and replace with <br/><span class="drop_caps_tab"/>.

That said you appear to be missing the closing </span> tag. This would make the search slightly more complicated as you would need account for the closing tag in your search. So for the example given, I suggest:

Search for <br/>\n("?[A-Z]) and replace with <br/><span class="drop_caps_tab"/>\n\1</span>.
Thank you so much - Search and Replace worked perfectly!

I am not missing the closing tag, these are both self-closing tags because they have /> in the end. I actually want an empty <span/> tag inserted because of the properties that it brings - it is simulating a tab through padding like so:

.drop_caps_tab {
padding-left: 0.6cm;
}

Last edited by LenaWolf; 11-29-2025 at 07:56 PM. Reason: Added CSS code for clarity.
LenaWolf is offline   Reply With Quote
Old 11-30-2025, 07:08 AM   #5
Quoth
Still reading
Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.
 
Quoth's Avatar
 
Posts: 15,188
Karma: 111120239
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper
Quote:
Originally Posted by LenaWolf View Post
Thank you so much - Search and Replace worked perfectly!

I am not missing the closing tag, these are both self-closing tags because they have /> in the end. I actually want an empty <span/> tag inserted because of the properties that it brings - it is simulating a tab through padding like so:

.drop_caps_tab {
padding-left: 0.6cm;
}
Better done by a class on the <p
Quoth is offline   Reply With Quote
Old 11-30-2025, 07:27 AM   #6
LenaWolf
Member
LenaWolf began at the beginning.
 
LenaWolf's Avatar
 
Posts: 23
Karma: 10
Join Date: Oct 2025
Device: Sony PRS-T3, Kobo Libra Colour
Quote:
Originally Posted by Quoth View Post
Better done by a class on the <p
No, that doesn't work on a <p>. I want the line after a line break to be indented, rather than the first line of the paragraph.
LenaWolf is offline   Reply With Quote
Old 11-30-2025, 11:41 AM   #7
Quoth
Still reading
Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.
 
Quoth's Avatar
 
Posts: 15,188
Karma: 111120239
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper
Quote:
Originally Posted by LenaWolf View Post
No, that doesn't work on a <p>. I want the line after a line break to be indented, rather than the first line of the paragraph.
A class to indent can be added to ANY tag.

There normally should be zero <br /> in body. Vertical spacing should be by class.

The only case I know that needs a <br /> is to break a title/heading onto two lines so automatic ToC generation sees it as one entry. Otherwise it's an obsolete throw back to before styles or classes.

A <br /> is like typing enter twice in the source. I search and delete blank lines, leading spaces, trailing spaces and tabs. I replace all spaces more than one with one.

Any <br /> in body text can he replace by single Search & Replace of
</p>
<p class="whatever">

Where css of whatever defines a top margin and desired indent, left, right etc.
Quoth is offline   Reply With Quote
Old 11-30-2025, 12:22 PM   #8
LenaWolf
Member
LenaWolf began at the beginning.
 
LenaWolf's Avatar
 
Posts: 23
Karma: 10
Join Date: Oct 2025
Device: Sony PRS-T3, Kobo Libra Colour
Quote:
Originally Posted by Quoth View Post
There normally should be zero <br /> in body. Vertical spacing should be by class.
It just depends on your source. My source is used to create several different formats, and in PDF this is where I use real drop caps which I replace by a layout with the first character being double the size in ePUB, without dropping it. I tried using floats, but it doesn't render reliably. So the line break is an artefact from a work-around from PDF where you have to combine several short paragraphs together in order to have your drop cap display in full size, such as over 4 lines instead of only 2. This combined paragraph then has a line break and a tab, and I wrap the tab into a character style which is translated into a padded style for ePub so that it looks just like a normal indent (I use indented text in regular paragraphs). That is to say, I no longer insert an indent after every line break, but instead I use character styling on the tab. And yes, I know, the tab disappears in ePUB, and that's fine, but the styling remains.

So my line breaks are not used to achieve vertical spacing at all but to make a work-around for full-sized drop caps in PDF which then needs to be smoothed over in ePUB. But I've got it figured out!
LenaWolf is offline   Reply With Quote
Old Yesterday, 06:50 PM   #9
Quoth
Still reading
Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.
 
Quoth's Avatar
 
Posts: 15,188
Karma: 111120239
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper
Do epubs FIRST, then a copy of source to do PDFs professionally.

Even so the same rules of no extra white space by tabs, empty lines or extra spaces apply. The styles work perfectly 1:1 to CSS and create perfect PDF if done correctly. At least Word since 2007 and version 3.x of Libre Office. That's a long time ago.
Quoth is offline   Reply With Quote
Old Yesterday, 09:43 PM   #10
LenaWolf
Member
LenaWolf began at the beginning.
 
LenaWolf's Avatar
 
Posts: 23
Karma: 10
Join Date: Oct 2025
Device: Sony PRS-T3, Kobo Libra Colour
Quote:
Originally Posted by Quoth View Post
Do epubs FIRST, then a copy of source to do PDFs professionally.

Even so the same rules of no extra white space by tabs, empty lines or extra spaces apply. The styles work perfectly 1:1 to CSS and create perfect PDF if done correctly. At least Word since 2007 and version 3.x of Libre Office. That's a long time ago.
The contents of the PDF is different from the contents of ePUB, so that wouldn't work. PDF also comes in a bilingual version as well as in single language versions. It has different illustrations which are larger, taking advantage of a larger page size. These versions of the book are produced from the same ODT sources with LibreOffice using master documents built up of different parts. The ePUB version is just one version, so I wish to avoid editing ePUB. I managed to make all styles with LibreOffice and apply a few rules through Calibre for the ePUB. And yes, there are a few work-arounds, although I do keep them to a minimum.

To clarify, I have one ODT document for the ePUB which contains text and graphics in the right places. I have another document for English PDF, another one for Portuguese PDF, a third one for the bilingual version PDF which I generate all directly from LibreOffice. All text sources of the book are simple ODT documents divided up into sections between which pictures can be placed in the files made for ePUB and the various PDFs. These text sections are imported into the master documents for each output type. Note that picture placement is different for each format because of the layout.

Because of this workflow, editing ePUB is undesirable for me because it is the last step in a long chain. Which is why I am working on the conversion rules for my specific needs.
LenaWolf is offline   Reply With Quote
Old Today, 01:29 PM   #11
Quoth
Still reading
Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.
 
Quoth's Avatar
 
Posts: 15,188
Karma: 111120239
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper
Quote:
Originally Posted by LenaWolf View Post
The contents of the PDF is different from the contents of ePUB, so that wouldn't work.
It's always better to do the ePub first. It can be converted from docx to epub and all text styles (character or paragraph) 100% map 1:1 to CSS and spans etc. Then can be proofed. Zero editing of HTML and text CSS. You might need to edit CSS (only) of some images.

PDFs can have headers, footers, columns, page numbers, footnotes at the bottom of the page, multiple page styles, differing margins for L & R (for binding), print registration (for each side of a leaf). An epub has none of these.

PDFs uses a design time size of paper. The epub has no paper size and is reflowable (yes there are fixed layout epub, but pointless compared to PDF).

The view of a PDF is fixed. The user can change L & R margins, line spacing and body font on epub.

[EDIT: If using LO Writer you edit odt files and do an extra docx save for epub conversion you never edit. You do true WYSIWG for PDF and export PDF direct from LO Writer. The odt file for epub can use a small paper size with tiny margins. Then when proofed a copy is edited and a template with styles for the PDF is applied. That changes spacings, margins, fonts and paper size. Next you add page styles for front matter, end matter, headings, footers, page numbers, true footnotes etc and finally edit the contents generation (or appendix / index etc) to have page numbers. Export PDF. Preview on 4K desktop or a Nxtpaper 14 tablet. Send PDF to Printer and it will be 100% correct.]

Last edited by Quoth; Today at 01:38 PM.
Quoth is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Tag: separate two sections by a small space to minimise user error paperback Editor 3 05-30-2022 06:53 AM
1. calibre_bookmarks.txt / 2. insert tag jiembe Calibre 5 12-05-2020 12:14 PM
html to EPUB - added class into <html> tag etihwmot Conversion 25 08-05-2020 05:20 PM
html img tag versus svg wrapped image tag hobnail ePub 8 02-27-2020 04:16 AM
Some questions or possible enhancements on Insert Tag tool? arspr Editor 6 05-10-2014 03:22 PM


All times are GMT -4. The time now is 03:27 PM.


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