maybe_haskell icon indicating copy to clipboard operation
maybe_haskell copied to clipboard

Code samples rendering wrong in iBooks

Open chriskrycho opened this issue 10 years ago • 8 comments

Throughout the ePub version, the monospace font for code samples is rendered incorrectly in iBooks if you choose any reading font besides "Original"—it appears the style sheet isn't overriding some of the classes. See here, for example (using Charter):

epub

As you can see, the bits that are wrapped in syntax highlighting spans (<span class="dt"> etc. in the XHTML source) are falling back to the main typeface instead of the monospace typeface.

chriskrycho avatar Mar 27 '15 12:03 chriskrycho

Thanks for reporting this. Strange, it looks like just the type signatures, not the function definitions are rendered in the wrong font.

@trevororeilly do you have any ideas?

pbrisbin avatar Mar 27 '15 16:03 pbrisbin

It does kind of look that way, but that's just a function of what gets highlighted; note that the highlighted bits (User, <$>, "name", "email",=, and <*>) all have the same issue—it's not obvious, but you can tell because they're the wrong widths.

chriskrycho avatar Mar 27 '15 16:03 chriskrycho

Ah, right I do see that now.

pbrisbin avatar Mar 27 '15 17:03 pbrisbin

@pbrisbin Apologies for not getting back sooner, was on client work for most of the day. Let me investigate and see what I can find.

trevororeilly avatar Mar 27 '15 22:03 trevororeilly

It looks like iBooks is doing something (Javascripty, maybe) that overrides these classes, possibly because they're span type elements. All the affected elements have custom attributes, __ibooks_font_override="true" and __ibooks_align_override="true"; it appears the former is what's causing the problem, and from what I can tell from reading up a bit, it looks like Apple applies this to all p, div, or span elements. And whatever Apple is doing there is making it so that no override I apply works; I've even tried getting as mind-boggling specific as a selector like code > span.kw[__ibooks_font_override="true"][__ibooks_align_override="true"] (and, for that matter, just setting a style attribute value on it directly in the inspector). Nothing works. :confused:

Edit: amusingly, setting a <font> inside those span tags works… but I can't exactly recommend that as a solution. :wink:

chriskrycho avatar Mar 28 '15 16:03 chriskrycho

Per SO, you can retain styles using iBooks Author, so it may be worth seeing what output that generates for something like this. It'll certainly entail more than just the pandoc output, unfortunately.

chriskrycho avatar Apr 01 '15 23:04 chriskrycho

@pbrisbin @trevororeilly How's this looking?

calebhearth avatar Sep 28 '15 14:09 calebhearth

When I read via the Kindle app on my phone (Nexus 5), I also see non-monospaced font for the code samples -- it does look correct on my actual Kindle though.

pbrisbin avatar Oct 08 '15 18:10 pbrisbin