View Single Post
Old 09-22-2022, 09:43 PM   #3
hobnail
Running with scissors
hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.
 
Posts: 1,552
Karma: 14325282
Join Date: Nov 2019
Device: none
JSWolf's answer assumes that your CSS is using classes. My CSS only specifies html tags; e.g.,
Code:
body {
  font-size: 100%;
  border: 0;
  margin: 0;
  padding: 0;
  width: auto;
}

body * {
  line-height: inherit;
}

p {
  font-size: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  text-indent: 2em;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,h2,h3,h4 {
  text-align: center;
}

.bold {
  font-weight: bold;
}

.italic {
  font-style: italic;
}

.bold_italic {
  font-weight: bold;
  font-style: italic;
}

img {
  margin-left: auto;
  margin-right: auto;
  max-width: 100%;
  border: none;
}
You can't merely append this to the existing CSS because the precedence rules state that when you have, for example,
Code:
<p class="calibre1">
the CSS for .calibre1 will have precedence over the CSS for the HTML p tag, even if the CSS for p is at the bottom of the file. So I do a select all in the stylesheet file and replace the original CSS with the above. There's CSS built into the Kobo that does a nice job as is so the above merely tweaks it (I think it's possible I could delete the two font-size lines).

My goal is to always have the same left and right margins, same line spacing, and same font size every time I open a book (in other words, they were set in the Kobo). Some things are lost with this, for example, spacing after chapter titles, particularly when fools used the p tag instead of one of the h tags.

The one thing I don't want to lose is the bold and italic stuff, so before nuking the book's CSS I search for classes with italic and bold and add those classes to the .bold and .italic (so that the CSS becomes something like ".bold,.calibre8,.calibre12 {"), and the ones that are both bold and italic are added to .bold_italic (and likewise underlined bold gets added to .bold_italic). The regular expression I use for searching for that stuff is "bold|italic|font-weight: [56789]"; some books use font-weight:400 to reset to normal, which isn't necessary with my scheme.

So the book's html and all of the classes, spans, and whatnot in the html are untouched. Some books will have spaces between paragraphs by using p tags around a space entity so when I see that nonsense I delete all of those with a global replace. Some use divs instead of ps for the paragraphs so I use Diap's toolbag plugin to replace the divs with ps.

Most of the time the epub was converted from the Kindle format. If it was an epub to begin with I do an epub to epub conversion so that calibre can clean the html, fixing inline styles and whatnot.

Last edited by hobnail; 09-22-2022 at 09:59 PM.
hobnail is offline   Reply With Quote