Ticket #4418 (closed defect: fixed)
epub: calibre overwrites list-style: none with list-style-type: disc
| Reported by: | minstrel | Owned by: | kovidgoyal |
|---|---|---|---|
| Priority: | minor | Milestone: | |
| Component: | EPUB Output | Version: | trunk |
| Keywords: | list-style, list-style-type, epub | Cc: |
Description
Problem:
The following problem occurs when converting from HTML to epub:
My HTML file contains an unordered list <ul> which has been styled using the "list-style: none" attribute. According to http://xhtml.com/en/css/reference/list-style-type/, "list-style" is a shorthand property for simultaneously specifying several "list" attributes, including "list-style-type".
When generating epub output, Calibre copies over the "list-style: none" from the input CSS, but additionally adds an attribute "list-style-type: disc".
This leads to a wrong list-style (discs are being rendered although originally it was specified that the list marker should be omitted)
Analysis:
It seems that Calibre is adding a "default" list-style-type to the style definition.
Proposal:
Alternative A)
Instead of BOTH copying over the original "list-style: none" attribute AND adding the "list-style-type: disc", Calibre should either analyze the "list-style" shorthand definition and break it down into atomic definitions (e.g. "list-style-type", "list-style-position" and "list-style-image").
Alternative B)
Calibre should analyze whether a specified "list-style" contains one of the allowed "list-style-type" literals; if this is the case, the "list-style-type: disc" specification WILL NOT be written to the output file.
Example: (code snippets)
Input from original HTML file:
ul {
list-style-type: none;
margin-left: 0em;
margin-bottom: 0em;
padding-left: 1.5em;
text-indent: -1.5em;
}
ul.conspirators {
margin-left: 3em;
}
Calibre output (stylesheet.css):
.conspirators {
display: block;
list-style: none;
list-style-type: disc;
margin-bottom: 0;
margin-left: 3em;
margin-right: 0;
margin-top: 1em;
padding-left: 1.5em;
text-indent: -1.5em
}
usage in the HTML:
<ul class="conspirators"> <li>Robert Catesby,</li> <li>Robert Winter</li> </ul>
Change History
comment:1 Changed 8 months ago by kovidgoyal
- Status changed from new to closed
- Resolution set to worksforme
comment:2 Changed 8 months ago by kovidgoyal
<html>
<head>
<style type="text/css">
ul {
list-style-type: none;
margin-left: 0em;
margin-bottom: 0em;
padding-left: 1.5em;
text-indent: -1.5em;
}
ul.conspirators {
margin-left: 3em;
}
</style>
</head>
<body>
<ul class="conspirators">
<li>one</li>
<li>two</li>
</ul>
</body>
</html>
comment:3 Changed 8 months ago by minstrel
While the workaround you describe certainly works, I don't believe it is very practical from a user perspective: In order to apply the workaround, the user needs to first know about the problem and then apply the workaround to the input CSS, e.g. alter the original document (that is what I did in the first place before reporting the bug). As the normal use case is more like that the user wants to import an existing HTML document and convert it to epub it seems to me that it should be Calibre's responsibility to handle "shortcut" tags like "list-style" correctly.
As this seems to bother just me I will try studying the Calibre source code in order to come up with a patch :)
comment:4 Changed 8 months ago by kovidgoyal
That's not a workaround. It's a demonstration that what you describe is not the problem.

Works for me with the following html