Register Guidelines E-Books Today's Posts Search

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

Notices

Closed Thread
 
Thread Tools Search this Thread
Old 07-15-2019, 03:51 PM   #1
MistaPrime
Member
MistaPrime began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Jul 2019
Device: EPUB
HTML to EPUB, how to keep classes?

We have foot notes that are links:

Code:
<a name="txt51" id="txt51"></a><a class="footnote" href="#ftn51" title="Note 51">51</a>
However the conversion removes the class footnote from the link.

The class is needed because the number 51 is a <sup> tag but made only using CSS.

If the class is removed it is not possible to style the link anymore to be a <sup>.

Is there any way from stopping Calibre from removing specific classes?
MistaPrime is offline  
Old 07-15-2019, 10:06 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
https://www.mobileread.com/forums/sh...d.php?t=186697
kovidgoyal is online now  
Advert
Old 07-16-2019, 03:25 PM   #3
MistaPrime
Member
MistaPrime began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Jul 2019
Device: EPUB
Quote:
Originally Posted by kovidgoyal View Post
That link only instructs us on how to submit a bug.

However this is not a bug.

It's what Calibre does by default.

If there is a link as shown in my previous reply, it will be converted to a link with it's own class, Calibre will give it a class on it's own. And it will remove the class called "footnote".

What I am asking is this; is it possible to instruct Calibre to keep the class "footnote"? Calibre could keep adding it's own classes but to keep that specific one?

It seem it would be simple to do that. Anyone know how?
MistaPrime is offline  
Old 07-16-2019, 03:44 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: 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 MistaPrime View Post
That link only instructs us on how to submit a bug.

However this is not a bug.

It's what Calibre does by default.

If there is a link as shown in my previous reply, it will be converted to a link with it's own class, Calibre will give it a class on it's own. And it will remove the class called "footnote".

What I am asking is this; is it possible to instruct Calibre to keep the class "footnote"? Calibre could keep adding it's own classes but to keep that specific one?

It seem it would be simple to do that. Anyone know how?
No
Calibre will analyze and make its changes/additions that are consistent with the other tasks it is performing.
Not all classes get changed. You may be doing something that is inconsistent with other (document wide) instructions, so it has to help it along.
theducks is offline  
Old 07-16-2019, 07:01 PM   #5
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,718
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by MistaPrime View Post
It seem it would be simple to do that. Anyone know how?
Long shot - try importing the html file into the a) calibre Book Editor (File=>Import an HTML or DOCX file as a new book) and/or b) Sigil (File->Add->Existing files)

BR
BetterRed is offline  
Advert
Old 07-16-2019, 09:06 PM   #6
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
calibre conversion will try to keep what existing classnames it can thaat are conistent with CSS flattening. That may or may not work for any particular class name. But what conversion will not do is remove formatting (unless you tell it to). So the visual appearance of the text from the input and output documents should be the same (or as similar as format differences allow).
kovidgoyal is online now  
Old 07-25-2019, 03:58 PM   #7
MistaPrime
Member
MistaPrime began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Jul 2019
Device: EPUB
Let's try it a different way;


Please convert this HTML: https://pastebin.com/Quk0kqxh
into the ePUB.

And the output of the footnote should look like this:

Click image for larger version

Name:	epub-sup-notes.png
Views:	483
Size:	72.0 KB
ID:	172571

Notice how the footnote number is styled as a superscript. Is smaller and higher than the rest of the text.

Can anyone do that using Calibre with that HTML?
If yes, how?

When I tried the footnote appeared like a regular text size, not a superscript. And it is because Calibre removes classes from footnote links.

Last edited by BetterRed; 07-25-2019 at 06:56 PM. Reason: Embed Image - (paper clip icon)
MistaPrime is offline  
Old 07-25-2019, 04:41 PM   #8
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: 195
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
Quote:
Can anyone do that using Calibre with that HTML?
If yes, how?
There may be ways using CSS, depending on what else is going on there. Here is one way: assuming Calibre will not let you depend on the classname, I have never seen Calibre mess with the values of the TITLE attribute. If all your footnote link titles contain the word "Note" as in your example, this CSS rule works in most user agents:

Quote:
a[title~="Note"] {
vertical-align: super;
font-size: 0.8em;
padding: 0 4px;
font-weight: bold;
}

Last edited by Brett Merkey; 07-25-2019 at 04:46 PM.
Brett Merkey is offline  
Old 07-25-2019, 08:51 PM   #9
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
No it is not because of classes, why dont you paste your own HTML into a standalone HTML and open it in a browser, you will see that the the footnote links are not rendered as superscripts. In order for them to be rendered as superscripts, the linked CSS files also need to be present to give the classes meaning. And if the linked CSS files are also present, calibre will use them. And just for completeness, here is an actual HTML snippet that uses classes for superscripts that will work in a browser and in calibre, because unlike the HTML you posted, it actually contains the style definitions.

Code:
<html><body><style>.ss { vertical-align:super}</style><p>A<span class="ss">superscript</span></p></body><html>
kovidgoyal is online now  
Old 07-25-2019, 09:37 PM   #10
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 46,155
Karma: 168983734
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Quote:
Originally Posted by MistaPrime View Post
Let's try it a different way;


Please convert this HTML: https://pastebin.com/Quk0kqxh
into the ePUB.

And the output of the footnote should look like this:

Attachment 172571

Notice how the footnote number is styled as a superscript. Is smaller and higher than the rest of the text.

Can anyone do that using Calibre with that HTML?
If yes, how?

When I tried the footnote appeared like a regular text size, not a superscript. And it is because Calibre removes classes from footnote links.
You are using a class 'footnote' which is not defined anywhere in the HTML snippet you posted. I ran a report in Sigil and came up with the attached image. You will notice that there are 13 style classes in the HTML. There are no CSS files to supply those classes.

In the HTML file, there are references to 3 stylesheets between the head and end of head tags:

Code:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Legislative Summary of Bill C-XX: </title>

<link rel="stylesheet" type="text/css" href="/Content/LOP/ResearchPublications/styles/2012pubs.css" media="screen"/>
<link rel="stylesheet" type="text/css" href="/Content/LOP/ResearchPublications/styles/2012pubs_print.css" media="print"/>


<!--Remove stylesheet below before posting. Only need stylesheets above -->
<link href="../../../Styles/2012pubs.css" rel="stylesheet" type="text/css" media="screen"/>
</head>
Are you expecting calibre to browse the internet searching for those stylesheets? When I download a page from the internet using Firefox, I use the Save Page As function which downloads the related files as well as the main page.
Attached Thumbnails
Click image for larger version

Name:	Style_classes_in_HTML_files.png
Views:	270
Size:	35.5 KB
ID:	172592  

Last edited by DNSB; 07-26-2019 at 05:59 PM.
DNSB is offline  
Old 07-29-2019, 09:17 AM   #11
MistaPrime
Member
MistaPrime began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Jul 2019
Device: EPUB
Quote:
Originally Posted by kovidgoyal View Post
No it is not because of classes, why dont you paste your own HTML into a standalone HTML and open it in a browser, you will see that the the footnote links are not rendered as superscripts. In order for them to be rendered as superscripts, the linked CSS files also need to be present to give the classes meaning. And if the linked CSS files are also present, calibre will use them. And just for completeness, here is an actual HTML snippet that uses classes for superscripts that will work in a browser and in calibre, because unlike the HTML you posted, it actually contains the style definitions.

Code:
<html><body><style>.ss { vertical-align:super}</style><p>A<span class="ss">superscript</span></p></body><html>
What if you had a client that that has thousands of pages that you cannot change? Which is in this case.

The links in the HTML are with a class footnote, it does not have a <sup> tag. And the HTML cannot be changed.

Calibre should be able to keep the class footnote in the link if we ask it to. Otherwise I am looking at manually editing thousands of pages just to make it work with Calibre.

The class footnote is used in a different stylesheet but that is not relevant. Calibre should leave the class footnote alone if we tell it to.
If a class is needed, it should have that option.

So far the best solution is the CSS offered by user Brett Merkey.
But that is not a solution for the long term.

Please give Calibre an option to keep a class if we mention that class.
MistaPrime is offline  
Old 07-29-2019, 11:45 AM   #12
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
@MistaPrime,

What a sense of entitlement you have! Lots of "calibre should do x" in there.

If you have a client who is paying you for a service then the onus is all on you to find a suitable solution. To tell a developer, who is not charging for his services what his software should/shouldn't be doing to make your professional life easier, quite frankly, beggars belief.

Of course you could have gone through the normal channel for requesting (nicely) a calibre enhancement and hoped for the best but you chose to try to dictate and belittle instead. Well, good luck with that approach, it rarely works.
jackie_w is offline  
Old 07-29-2019, 11:46 AM   #13
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 46,155
Karma: 168983734
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Quote:
Originally Posted by MistaPrime View Post
What if you had a client that that has thousands of pages that you cannot change? Which is in this case.

The links in the HTML are with a class footnote, it does not have a <sup> tag. And the HTML cannot be changed.

Calibre should be able to keep the class footnote in the link if we ask it to. Otherwise I am looking at manually editing thousands of pages just to make it work with Calibre.

The class footnote is used in a different stylesheet but that is not relevant. Calibre should leave the class footnote alone if we tell it to.
If a class is needed, it should have that option.

So far the best solution is the CSS offered by user Brett Merkey.
But that is not a solution for the long term.

Please give Calibre an option to keep a class if we mention that class.
As the title of this thread states: HTML to EPUB, how to keep classes?"

If you have a class in a stylesheet, calibre will not remove it fom the HTML files. If you don't have a class used in the HTML that is not in a stylesheet, it is an unused reference and will be removed. Even if calibre left an unused class in the HTML, it would not work since there is no stylesheet to supply the information for that class. This leaves out calibre's habit of flattening stylesheets but that still leaves a class in the HTML. Or are you planning to adding a stylesheet into the epub after using calibre to create it in a frenzy of manual editing?

So stop trying to convert a naked HTML file to an epub. What you should be doing is generating a file with the HTML and CSS files so calibre has that information available. You can download the webpage and add the files into a .zip file and then use calibre on that .zip file to generate an epub which includes the HTML and CSS (plus any downloaded images, etc.) which you then edit to remove the cruft.

Edit: I noticed you used the term "we" and not I several times in your posts. Given that the HTML you posted appears to be from a Canadian government site, you should consider hiring someone semi-competent. Someone who might understand a a webpage is not just the raw HTML files but the supporting code (CSS stylesheets, javascript, etc.).

Last edited by DNSB; 07-29-2019 at 12:10 PM. Reason: Added comment about "we"...
DNSB is offline  
Old 07-29-2019, 02:05 PM   #14
MistaPrime
Member
MistaPrime began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Jul 2019
Device: EPUB
Quote:
Originally Posted by jackie_w View Post
@MistaPrime,

What a sense of entitlement you have! Lots of "calibre should do x" in there.

If you have a client who is paying you for a service then the onus is all on you to find a suitable solution. To tell a developer, who is not charging for his services what his software should/shouldn't be doing to make your professional life easier, quite frankly, beggars belief.

Of course you could have gone through the normal channel for requesting (nicely) a calibre enhancement and hoped for the best but you chose to try to dictate and belittle instead. Well, good luck with that approach, it rarely works.
I don't know how you read between the lines like that but it certainly is a skill you should avoid using.

There is no "sense of entitlement" in there, only your sense of pointlessly reading between the unnecessary lines and your sense of absurdity along with your sense of being very wrong.

In my view Calibre "should" have that option, that is not an order or demand, that is just a suggestion.

I thank you all for your input on this, I will definitely use the CSS suggestion as that is the quickest and most suitable work-around for this purpose.
MistaPrime is offline  
Old 07-29-2019, 02:12 PM   #15
MistaPrime
Member
MistaPrime began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Jul 2019
Device: EPUB
Quote:
Originally Posted by DNSB View Post
Or are you planning to adding a stylesheet into the epub after using calibre to create it in a frenzy of manual editing?

So stop trying to convert a naked HTML file to an epub. What you should be doing is generating a file with the HTML and CSS files so calibre has that information available. You can download the webpage and add the files into a .zip file and then use calibre on that .zip file to generate an epub which includes the HTML and CSS (plus any downloaded images, etc.) which you then edit to remove the cruft.
Indeed, I was planning on adding a stylesheet/CSS to Calibre's custom CSS option.

Thanks for your suggestion, I appreciate that.

Quote:
Edit: I noticed you used the term "we" and not I several times in your posts. Given that the HTML you posted appears to be from a Canadian government site, you should consider hiring someone semi-competent. Someone who might understand a a webpage is not just the raw HTML files but the supporting code (CSS stylesheets, javascript, etc.).
The HTML above was found by Googling "footnote styles", I frankly didn't even notice it was from a Gov site but that does prove a bigger point, that even larger sites do not use <sup> in their HTML.

Regarding the competency level comment, I am not good at reading between the lines but if you are attempting to judge my competency in HTML based on the request above, you may want to re-read the request.

Thanks for the input, your help has been greatly appreciated.
MistaPrime is offline  
Closed Thread


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pseudo classes to be deleted as unused classes Leonatus Sigil 2 09-23-2018 09:12 AM
docx to epub - obsolete classes for italic and bold krbo Conversion 2 01-09-2014 05:44 AM
CSS classes on Android epub readers MarleneW ePub 7 05-13-2012 04:57 PM
txt to Epub - adding classes with textile Nareshkendel Conversion 4 11-23-2011 05:30 PM
Why, During ePub to ePub Conversion does Calibre changes existing CSS classes? JSWolf Conversion 7 08-06-2011 07:32 PM


All times are GMT -4. The time now is 03:53 AM.


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