![]() |
#1 | |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Jan 2017
Device: iPad
|
Pre-formatted code snippet renders badly
I have an epub that contains Python code snippets which are not rendered correctly (see attached screenshot).
Looking into the source code of the epub file, the code fragments are correctly wrapped with XHTML tags. Quote:
Last edited by CBSA; 01-19-2017 at 07:47 AM. |
|
![]() |
![]() |
![]() |
#2 |
Not Quite Dead
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 195
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
The problem is not the CSS. The example is rendering as coded. PRE tags are block elements. Anything tagged as such will render with whitespace and separate from other elements. Are the CODE classes styled as inline or block?
Last edited by Brett Merkey; 01-19-2017 at 07:58 AM. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Jan 2017
Device: iPad
|
Thank you very much for answering! How may I find out about this question? Shall I search for a CSS selector for classes "n", "p" and so on?
|
![]() |
![]() |
![]() |
#4 |
Not Quite Dead
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 195
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
"Shall I search for a CSS selector for classes "n", "p" and so on?"
Yes. If one PRE tag surrounds all those instances of CODE tags, then the problem may be that the classes referred to in the CODE tags may be forcing the default inline CODE snippets to display as block elements—which is definitely not what you want. Perhaps look for "display: block" declarations and delete them. |
![]() |
![]() |
![]() |
#5 | |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Jan 2017
Device: iPad
|
Well, I don't see any problems with the CSS code:
Quote:
|
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Jan 2017
Device: iPad
|
Further tests
I coded now explicitly "display: block;" and "display: inline;" into the code CSS selector and could see that it makes a difference. I think the code elements are already inline elements.
My current line of thoughts is once again that it has to do with the setting "data-language-type: python" inside the pre element. For some reason, this style sheet is not applied. Could be related to the webkit references!? |
![]() |
![]() |
![]() |
#7 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 78,971
Karma: 144284074
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Do not use a PRE tag. ADE has this wonderful bug where the text in the PRE tag does not wrap but goes off the screen.
|
![]() |
![]() |
![]() |
#8 |
Not Quite Dead
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 195
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
<<I don't see any problems with the CSS code>>
Agree. The structural and style code display as expected in both my browser and Calibre. It is interesting that the one-letter classnames mentioned in the html are not specified in the css snippet. |
![]() |
![]() |
![]() |
#9 |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Jan 2017
Device: iPad
|
Hi Brett!
No, they are defined somewhere else in the CSS file. But they only code for different colors. So far, I don't see how the lines of code and newlines are coded with help of the code tags. They enclose individual words and symbols, so even if they were shown all in a line, the newline characters would be missing. |
![]() |
![]() |
![]() |
#10 |
Not Quite Dead
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 195
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
Thanks for the clarification on those classes. I further experimented but found nothing. I was suspicious of the overflow-wrap property in the CODE rule. Sometimes if a CSS property which is meant for block elements is applied to an inline element, a user agent will "helpfully" convert the inline element to a block element. But taking the property out did nothing--and the W3C specs say the property should apply to all elements anyway.
A mystery... |
![]() |
![]() |
![]() |
#11 |
Not Quite Dead
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 195
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
@CBSA, for forensic purposes you could add a !important statement to the rule for CODE, like so:
code {display: inline !important;} This is equivalent to using a shotgun to clear a clogged pipe (deer-in-headlight coding!) but it could indicate whether the problem has anything to do with the CODE tag at all. |
![]() |
![]() |
![]() |
#12 | |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 78,971
Karma: 144284074
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
|
|
![]() |
![]() |
![]() |
#13 |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Jan 2017
Device: iPad
|
|
![]() |
![]() |
![]() |
#14 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 78,971
Karma: 144284074
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
|
![]() |
![]() |
![]() |
#15 |
Junior Member
![]() Posts: 1
Karma: 10
Join Date: Feb 2017
Device: Kindle
|
I had a similar problem and the best solution I could find was to change both the pre and code class white-space CSS element from "pre-wrap" to "normal". This at least gets them on the same line, but it is not a perfect fix. Maybe someone can uncover the final pieces to the puzzle.
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
find badly formatted ebooks | alexxxm | Calibre | 3 | 05-29-2016 12:33 PM |
The Adventures of Joe Nobody and the Badly Formatted Epub | mklynds | Sigil | 44 | 01-30-2013 02:43 PM |
Badly formatted eBooks | Katsunami | General Discussions | 27 | 02-03-2012 11:49 AM |
Touch A badly formatted book or bad Kobo Touch rendering? | jswinden | Kobo Reader | 16 | 07-07-2011 07:19 PM |
Classic Bought a Badly Formatted Book From B&N | lionel47 | Barnes & Noble NOOK | 11 | 05-22-2010 04:31 PM |