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 09-04-2014, 12:47 PM   #1
paipa
Member
paipa began at the beginning.
 
Posts: 12
Karma: 10
Join Date: Nov 2013
Device: Kindle Paperwhite 2
--extra-css argument ignored

Hi! I tried searching for this problem on the board but I only found an empty thread from three years ago.

I use the command line conversion utility on a Linux Mint 17 machine using calibre 2.1.0. I have a Markdown-formatted txt file. I'll copy the command below so you see the exact settings I'm using.

Code:
ebook-convert mybook.txt mybook.azw3 --remove-paragraph-spacing --remove-paragraph-spacing-indent-size 1.0 --output-profile kindle_pw --formatting-type markdown --paragraph-type off --markdown-extensions tables --extra-css "custom_markdown.css"
But my custom CSS just won't be used. I tried it with --extra-css="custom_markdown.css" or without quotes... no luck. The conversion runs through fine (no errors whatsoever) and the CSS itself isn't corrputed either. I can open the azw3 file with the graphical editor and paste my CSS into one of the two css files and it works then. But not from the command line.

Just putting it here, it might be worth looking into.
paipa is offline   Reply With Quote
Old 09-04-2014, 01:07 PM   #2
paipa
Member
paipa began at the beginning.
 
Posts: 12
Karma: 10
Join Date: Nov 2013
Device: Kindle Paperwhite 2
I realized I should have given you example files. I'll copy a sample markdown txt file below, and under that the very simple css that I'm using.

Code:
# First Chapter

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce lacinia odio nec varius vestibulum. Phasellus efficitur cursus sapien, eu sollicitudin felis cursus quis. Donec rhoncus risus nulla, id finibus ante porttitor nec. Aenean elementum, velit nec venenatis consectetur, quam felis convallis tortor, nec vestibulum arcu mauris quis sapien. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.

Proin nec arcu et ligula facilisis sagittis. Quisque imperdiet vulputate dui nec volutpat. Fusce pulvinar arcu eu maximus pulvinar. In lacinia mauris condimentum sollicitudin accumsan. Vestibulum gravida consequat viverra. In sit amet felis mauris. Duis facilisis turpis nec fermentum dictum. Integer pulvinar ut velit sit amet sodales. Morbi urna sem, finibus eget molestie eget, porta nec neque.

Integer feugiat sapien eros, non egestas lacus venenatis in. Suspendisse eget orci euismod metus vulputate tincidunt in vitae nisi.

+ Nam congue turpis a ex sollicitudin mollis. Nunc tempus egestas nisl vel sagittis. Mauris vestibulum aliquet ex at ornare.

+ Cras vehicula ullamcorper nulla sed fermentum. Nulla porttitor, diam vitae convallis porttitor, dolor odio euismod est, quis tristique sapien nisl eget lectus.

+ Aliquam erat volutpat. Nulla et felis lacus. Nam ut dolor posuere, ultrices nulla vitae, ultricies nisi.

Sed lobortis arcu sed aliquam posuere. Ut nec magna nulla. Donec dignissim dignissim lobortis. Duis vel enim turpis. Nam sem elit, dapibus vel venenatis molestie, imperdiet vel nulla. Suspendisse ornare sapien vitae orci bibendum, quis pharetra erat lacinia.

Suspendisse at ipsum congue, posuere velit eget, congue erat. Nulla ac congue nisl. Phasellus a ligula non odio faucibus egestas. Mauris enim lacus, eleifend non porttitor eu, sagittis ac elit. Duis egestas auctor mauris in tempor. Curabitur eu luctus magna. Maecenas rhoncus, lacus a euismod vestibulum, velit orci rhoncus justo, quis euismod libero mi volutpat risus.

----

Proin sodales, mauris id porttitor iaculis, libero erat rhoncus quam, in rutrum tellus risus sit amet mi. Mauris ac accumsan tortor. Nulla convallis hendrerit odio et ornare. Morbi ac libero quis lectus sagittis tristique vel eget velit.

Cras tincidunt tincidunt nunc, et fringilla enim blandit quis. Maecenas arcu sapien, dapibus sit amet volutpat at, suscipit vel ligula. Vestibulum imperdiet convallis iaculis. Fusce vitae turpis eros. Phasellus sed ante purus. Nullam volutpat eleifend augue at aliquet. Suspendisse in aliquam dolor, quis dapibus nisi. Morbi mattis, ipsum vel porttitor faucibus, quam eros suscipit mauris, sed facilisis diam lacus eget nisl.

Maecenas ipsum urna, sodales a semper vitae, rhoncus eu tellus. Donec iaculis viverra mauris id viverra. Duis in lacus vitae ligula egestas volutpat. Curabitur odio felis, dignissim quis finibus ut, imperdiet mattis diam. Mauris vel ornare tortor. Nullam eget enim et lectus ultrices ullamcorper. Vivamus sit amet ipsum quam. 

# Second Chapter

Etiam eget nunc vel ligula pulvinar convallis. Vestibulum ut vestibulum turpis, in viverra nisl. Curabitur et eros felis. Nulla laoreet tortor id gravida iaculis. Sed felis ligula, consectetur at ullamcorper ut, tincidunt non arcu. Nullam blandit diam eget risus sollicitudin, in porttitor felis ullamcorper. Phasellus sed viverra ante, quis tincidunt neque.

Aenean eu fringilla ante. Sed nisl erat, bibendum ut velit sed, porta blandit nibh. Integer cursus nisi eget sem placerat interdum. Integer vitae elementum arcu, non bibendum dolor. Donec eget bibendum erat. Integer eget interdum purus. Vestibulum a semper tortor, at porta erat. In dolor nulla, vestibulum et congue a, tristique non augue. Ut quis placerat enim. Suspendisse quis orci eu nisi pretium sagittis ac eget nulla.

----

Sed tincidunt turpis id nisl mattis bibendum. Nunc dapibus arcu quis turpis vestibulum vehicula. Quisque blandit velit quis nisi gravida ultrices. Proin ut accumsan sapien. Nullam at commodo justo, non semper velit. Duis ultrices eleifend orci id venenatis.

Pellentesque non faucibus lacus. Nullam sollicitudin at leo ac vehicula. Nunc purus augue, vehicula eu tortor eget, mattis pretium elit. Duis interdum sed velit ac tristique. Aenean vulputate pulvinar pulvinar. Sed feugiat laoreet felis a bibendum.

Nullam eget erat cursus, dapibus nisi eget, tristique risus. Nunc ut accumsan enim. Nam enim libero, gravida id metus sit amet, varius rhoncus purus. Phasellus eu efficitur tellus, in ultrices massa. Mauris aliquet nec elit at pretium. Cras sit amet arcu quam. Nunc bibendum mauris eu leo sollicitudin tempus.

> Donec semper rhoncus dui, ac consequat massa tempor eu. Sed non sem tortor. Ut pellentesque odio ut quam auctor mattis.

> Suspendisse a elit faucibus, aliquet elit eget, volutpat lectus. Aenean non tellus blandit, faucibus mauris non, iaculis dolor. Morbi quis quam nisl. Nullam vel mi tortor. Curabitur sit amet lacus quis diam faucibus viverra luctus a justo. Vestibulum nec ornare erat.

> Ut nec eros sed enim lacinia pellentesque vel in nunc. Fusce aliquet nisl a diam molestie tristique.

Pellentesque tempus diam nec laoreet consequat. Maecenas rhoncus at erat non hendrerit. Vestibulum sagittis, augue vitae venenatis fermentum, libero diam pulvinar quam, nec placerat lorem tortor vel odio. Maecenas lobortis, lacus sed egestas varius, arcu quam sagittis nunc, quis finibus augue magna et justo.

In eleifend mauris ut aliquet aliquet. Maecenas vel suscipit odio, ut vestibulum elit. Suspendisse ac mattis dolor. Vivamus vitae pharetra mi. Fusce aliquam vitae metus ac rhoncus.

# Third Chapter

Aliquam erat volutpat. Donec quis lacus tempor, luctus quam nec, ullamcorper lorem. Vivamus nec ipsum hendrerit, hendrerit enim ac, faucibus augue. Vestibulum at condimentum tortor. Mauris at quam non metus congue suscipit. Pellentesque at est at massa blandit fermentum.

Donec ac volutpat eros. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas vulputate vel nunc at finibus. Fusce eget tortor eu orci malesuada varius et sit amet est. Sed imperdiet felis tortor, mollis mollis ante aliquet at.

In consectetur mattis ultrices. Nullam vehicula, urna vulputate malesuada scelerisque, magna sapien rhoncus lacus, eget venenatis odio leo a elit. Nunc tempus mi sed aliquet ultricies. Quisque nisl risus, ornare et nisl at, lobortis gravida magna. Sed vulputate ligula sapien, ac laoreet velit rutrum sit amet.

----

Nam nec commodo nibh. In nisl nisi, luctus in neque eget, scelerisque cursus sapien. Nulla suscipit sodales nisi, et dapibus urna tincidunt bibendum.

Fusce placerat tempor sem, sit amet lacinia eros imperdiet in. Vivamus vestibulum ipsum at dui sollicitudin, nec rhoncus ipsum sodales. Integer porta iaculis tellus, non eleifend nisi malesuada et. Mauris ac erat interdum, luctus ligula eu, sagittis nibh. Quisque imperdiet ex magna.

And the CSS:

Code:
hr { visibility: hidden; }
h1 + p, h2 + p, h3 + p, blockquote + p, hr + p { text-indent: 0 !important; }
blockquote { font-style: italic; }
blockquote > p { text-indent: 0 !important; padding-top: 0.25em !important; }
h4 { display: none; }
li > p { display: inline; }
li > p { text-indent: 0 !important; }
paipa is offline   Reply With Quote
Advert
Old 09-04-2014, 01:34 PM   #3
PeterT
Grand Sorcerer
PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.
 
PeterT's Avatar
 
Posts: 12,236
Karma: 74000000
Join Date: Nov 2007
Location: Toronto
Device: Nexus 7, Clara, Touch, Tolino EPOS
Try adding some path. info to the file name (ie --extra-css "./custom_markdown.css" or possibly --extra-css "/the/path/where/the/file/exists/custom_markdown.css"

From the help
Quote:
--extra-css
Either the path to a CSS stylesheet or raw CSS. This CSS will be appended to the style rules from the source file, so it can be used to override those rules.
PeterT is offline   Reply With Quote
Old 09-04-2014, 01:55 PM   #4
paipa
Member
paipa began at the beginning.
 
Posts: 12
Karma: 10
Join Date: Nov 2013
Device: Kindle Paperwhite 2
Quote:
Originally Posted by PeterT View Post
Try adding some path. info to the file name (ie --extra-css "./custom_markdown.css" or possibly --extra-css "/the/path/where/the/file/exists/custom_markdown.css"

From the help
Thanks for the tip. Actually having taken a closer look, Calibre DID use the file, but only parts of it. The blockquote parts are italic and the bullet point lists are also unindented, both of which I defined in the CSS. But it doesn't respect the "no indent for first paragraphs after h1/h2/h3/hr" rule and neither the "no indent in blockquote" nor the "0.25em padding in blockquote paragraphs" rules.

So now we know it's a problem with processing and importing these CSS rules rather than accessing them.
paipa is offline   Reply With Quote
Old 09-04-2014, 11:05 PM   #5
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: 43,965
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
extra css will not magically override styles defined in the input document. In this case, whatever styles are produced by the markdown converter. Only if a rule in extra css has higher specificity than a rule in the input document will it be applied.
kovidgoyal is offline   Reply With Quote
Advert
Old 09-05-2014, 03:32 AM   #6
paipa
Member
paipa began at the beginning.
 
Posts: 12
Karma: 10
Join Date: Nov 2013
Device: Kindle Paperwhite 2
Quote:
Originally Posted by kovidgoyal View Post
extra css will not magically override styles defined in the input document. In this case, whatever styles are produced by the markdown converter. Only if a rule in extra css has higher specificity than a rule in the input document will it be applied.
I don't think I get what "specificity" means in this context. A selector such as h1 + p is more specific than everything else in the post-conversion CSS. If I add it to the CSS after conversion with the GUI editor, they are applied, the DO override the styles already present and the book looks fine. No "magic" is needed here.

I see that calibre doesn't ever use element selectors in the CSS, but creates classes that it assigns to elements (calibre1, calibre2, etc.) which I suppose is a limitation here unless it has the capability of computing all p tags that are preceded by h1, creating a .calibre567 class and explicitly assigning it to them.
paipa is offline   Reply With Quote
Old 09-05-2014, 03:49 AM   #7
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: 43,965
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Its not the post conversion css that matters, it is the *pre* conversion css, extra css acts simply like adding an extra <style> tag in every html file in the input document.

Use the --debug-pipeline option.
kovidgoyal is offline   Reply With Quote
Old 09-05-2014, 07:05 AM   #8
paipa
Member
paipa began at the beginning.
 
Posts: 12
Karma: 10
Join Date: Nov 2013
Device: Kindle Paperwhite 2
Thanks, I looked at it, but I'm afraid I still don't understand it. In the input/parsed/processed folder there's pretty much just an unstyled index.html. A pagebreak or two get added in the parsed and processed steps, but nothing much. I don't see any sources of conflict. But I don't know this stuff well enough, so please just answer me one question.

How come that from the extra CSS file I pasted above, styling for "li > p" makes its way into the output, but "blockquote > p" and "h1 + p" don't?

And by the way (I know I'm coming off as a pain in the ass, but I'm actually interested in this) why does Calibre clutter up every single element with classes (i.e. every <hr> in my document looks like <hr class="calibre4">, every <h1> element is <h1 class="calibre2"> and so on) instead of using element-level selectors in the CSS and only assign classes for the exceptions (which in 80% of the cases don't even exist)?

I mean, if every h1 element is of class "calibre2", and everything that has "calibre2" class is an h1, then what's the point? And this holds for almost all elements in my document.
paipa is offline   Reply With Quote
Old 09-05-2014, 07:56 AM   #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: 43,965
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Sigh. This has been explained many times before. Google is your friend. Small hint: Think about the problem of trying to change styling on some individual element while not changing styles on any other element with cascading selectors, without relying on hacks like !important. And just to help you connect the dots, the css output by calibre is deliberately not cascading.
kovidgoyal is offline   Reply With Quote
Old 09-05-2014, 08:15 AM   #10
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: 43,965
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
And I tried running your samples and as far as I can see all applicable css from extra css is present in the output.

Namely, paragraphs after heading tags have zero text-indent and parapgrahs inside blockquotes have padding 0.25 em and zero text indent. See attached azw3.
Attached Files
File Type: azw3 huh.azw3 (15.0 KB, 110 views)

Last edited by kovidgoyal; 09-05-2014 at 08:23 AM.
kovidgoyal is offline   Reply With Quote
Old 09-05-2014, 10:50 AM   #11
paipa
Member
paipa began at the beginning.
 
Posts: 12
Karma: 10
Join Date: Nov 2013
Device: Kindle Paperwhite 2
Quote:
Originally Posted by kovidgoyal View Post
And I tried running your samples and as far as I can see all applicable css from extra css is present in the output.

Namely, paragraphs after heading tags have zero text-indent and parapgrahs inside blockquotes have padding 0.25 em and zero text indent. See attached azw3.
So now I get that what ruins it is --remove-paragraph-spacing --remove-paragraph-spacing-indent-size 1.0 in the command line call (which you haven't included because none of the paragraphs look indented to me).

In your azw3 file the first paragraphs after heading tags now indeed have a different class (calibre2 instead of calibre3 for the rest) allowing them to be styled differently. But when I used those two command line options, they were applied at the end of the pipeline, and ruined my up-to-that-point-unindented paragraphs. Now I get it.

So at the end of the day, I should emulate those two paragraph-formatting command line options in my own CSS (defining a custom p with zero margins, 1em indent etc) and it would be fine. Thanks a lot.
paipa is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Extra CSS and class renaming fenuks Recipes 4 01-26-2014 05:24 AM
--extra-css doesn't seem to work dawood Conversion 4 10-19-2013 09:23 AM
Justification problem even with extra css hiperlink Recipes 2 03-09-2011 08:40 AM
css pseudo elements and adjacent combinators in extra css? ldolse Calibre 2 12-21-2010 05:09 PM
a few extra css questions marbs Recipes 12 11-20-2010 10:15 AM


All times are GMT -4. The time now is 04:31 PM.


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