Problem with unknown CSS class
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
calibre |
Won't Fix
|
Undecided
|
Unassigned |
Bug Description
When converting some HTML fetched from somewhere with possibly incomplete or buggy CSS information, the conversion to EPUB introduces problematic class assignments, e.g. consider the following HTML:
<?xml version='1.0' encoding='utf-8'?>
<html xmlns="http://
<head>
</head>
<body class="calibre">
<p class="foobar">Some text</p>
<p>More text</p>
</body>
</html>
The class 'foobar' has no CSS information here. There may be no CSS information in a stylesheet or a link to a stylesheet may be broken. Now after adding this HTML as a book and converting to EPUB, the contents of the converted file are:
<?xml version='1.0' encoding='utf-8'?>
<html xmlns="http://
<head>
<title>
<meta http-equiv=
<link href="styleshee
<link href="page_
</head>
<body class="calibre">
<p class="foobar">Some text</p>
<p class="foobar">More text</p>
</body>
</html>
The definition of foobar in the generated stylesheet is:
.foobar {
display: block;
margin: 1em 0
}
Regarding the rendering of the HTML as it is, this is no problem. However, a possibly relevant distinction has been erased. For instance, when editing the EPUB and looking through the files, one may notice that the foobar class means centering for the stage directions in a drama. If one changes the rendering based on these semantics, the changes will now apply to other paragraphs, for which they are not appropriate. Consider something like:
.foobar {
text-align: left;
font-style: italic;
}
.foobar:before {
content:"Stage direction: ";
}
The resulting problems can easily go unnoticed, if there are only a few instances of this class attribute in some big ebook.
Therefore the distinction should be preserved and the result should be
<p class="foobar">Some text</p>
<p class="
or even better
<p class="foobar">Some text</p>
<p>More text</p>
I am aware that this ist not a Calibre bug in the strict sense, since the input is defective. However, since the result appears to be ok and the flaws can easily go unnoticed, these defects should be handled graciously.
Tested with Calibre 2.60 / Ubuntu 15.10.
Conversion flattens CSS, that is by design. The goal of conversion is to
preserve visual appearance, and produce output lkely to work on the
largest array of devices, while giving users automated control over CSS
transformations. Preserving input CSS is incompatible with those goals.
If you want to preseve input CSS import your html file into the editor
directly via File->Import and HTML or DOCX file as new book.
status wontfix