Compiling for Kindle: underlines

bo
bostonquad
Posts: 41
Joined: Tue Nov 28, 2017 7:12 pm
Platform: Mac

Tue Jan 02, 2018 1:15 am Post

My Kindle came with a user manual that uses thick underlines for hyperlinks. Here's a closeup:
s2.jpg
s2.jpg (170.56 KiB) Viewed 2393 times

When I compile to Kindle Mobi, my underlines look rather weak:
w2.jpg
w2.jpg (159.93 KiB) Viewed 2393 times

If I compile to Kindle KF8, the underlines disappear completely.
Can someone suggest how to get underlines to appear on the Kindle as they do in the first photo?
Thanks!

User avatar
nontroppo
Posts: 1067
Joined: Mon Mar 05, 2007 5:22 pm
Platform: Mac
Location: Airstrip One

Tue Jan 02, 2018 1:38 am Post

You will need to add a bottom border to your links. Edit your current compile format and add this text to the custom CSS section:

Code: Select all

a { text-decoration: none!important; border-bottom: 2px solid black!important; }


Screen Shot 2018-01-02 at 09.35.27_SMALL.png
Screen Shot 2018-01-02 at 09.35.27_SMALL.png (129.12 KiB) Viewed 2387 times


I don't own a kindle, but this works with EPub3 anyway...

bo
bostonquad
Posts: 41
Joined: Tue Nov 28, 2017 7:12 pm
Platform: Mac

Wed Jan 03, 2018 6:38 pm Post

This looks exactly like what I'm looking for; thank you!
Unfortunately, it doesn't seem to work (and I tried both mobi and epub compiles).
However, Scrivener is new to me, so I suspect I need to learn more about compiling in general.
I do understand CSS, so I have a chance of getting this to work if I can figure out the Scrivener part.

User avatar
nontroppo
Posts: 1067
Joined: Mon Mar 05, 2007 5:22 pm
Platform: Mac
Location: Airstrip One

Thu Jan 04, 2018 1:53 am Post

Check if this project works for you (it does for me for EPub3).

Scrivener Test.scriv.zip
(76.79 KiB) Downloaded 61 times


Screen Shot 2018-01-04 at 09.53.25.png
Screen Shot 2018-01-04 at 09.53.25.png (13.65 KiB) Viewed 2306 times

bo
bostonquad
Posts: 41
Joined: Tue Nov 28, 2017 7:12 pm
Platform: Mac

Fri Jan 05, 2018 7:15 am Post

nontroppo wrote:Check if this project works for you


It's pretty close - thank you! (It looks like text-decoration: none is not being respected. Maybe a bug?)
This is closer than I got, and I can use this for now.

When I have more time, I expect to track down what I missed.
IMG_7420.jpg
IMG_7420.jpg (65.49 KiB) Viewed 2252 times

User avatar
nontroppo
Posts: 1067
Joined: Mon Mar 05, 2007 5:22 pm
Platform: Mac
Location: Airstrip One

Fri Jan 05, 2018 8:07 am Post

Can you edit the mobi file that does what you want and see what the CSS says? text-decoration is the most basic of CSS rules, strange if it didn't support it! Perhaps there is another problem to do with the parent element of the links?
There are some very poorly supported extensions of the CSS text-decoration rules so maybe it is using those (which would make kindle an exception)?

https://developer.mozilla.org/en-US/doc ... e-position

bo
bostonquad
Posts: 41
Joined: Tue Nov 28, 2017 7:12 pm
Platform: Mac

Sun Jan 07, 2018 6:35 am Post

nontroppo wrote:Can you edit the mobi file that does what you want and see what the CSS says?


Thanks for the suggestion, but I can't even confirm the user manual is a mobi file. I don't see how to access it (or my other Kindle ebooks) at the file level.

bo
bostonquad
Posts: 41
Joined: Tue Nov 28, 2017 7:12 pm
Platform: Mac

Thu Jan 11, 2018 5:37 am Post

Ah! I have more insight, leading to a new question...

The insight: based on what I read here and here, I need to use Amazon's own non-standard <mbp:nu> tag to get the underline to not happen (nu means no underline). Apparently, Kindle ignoring text-decoration:none is a known issue.

So my new question...
How do I get this to be part of the Scrivener compile? I see how to add CSS, but not HTML tags.

User avatar
nontroppo
Posts: 1067
Joined: Mon Mar 05, 2007 5:22 pm
Platform: Mac
Location: Airstrip One

Thu Jan 11, 2018 6:12 am Post

You can use a character style in the editor to wrap your links:
Screen Shot 2018-01-11 at 14.01.55_SMALL.png
Screen Shot 2018-01-11 at 14.01.55_SMALL.png (32.21 KiB) Viewed 2076 times


And use prefix/suffix to add the HTML tags:

Screen Shot 2018-01-11 at 14.02.51_SMALL.png
Screen Shot 2018-01-11 at 14.02.51_SMALL.png (13.99 KiB) Viewed 2076 times


This creates this HTML in the .mobi:
Screen Shot 2018-01-11 at 14.08.07.png
Screen Shot 2018-01-11 at 14.08.07.png (23.29 KiB) Viewed 2076 times


The problem is this won't apply to the automatically generated TOC, only text with this style applied manually. For the TOC, you could just create your TOC manually, or edit the mobi file to wrap the TOC in the <mbp:nu> tag.

Why Kindle doesn't support such a basic CSS rule, and forces authors to inject non-standard HTML is beyond me...

bo
bostonquad
Posts: 41
Joined: Tue Nov 28, 2017 7:12 pm
Platform: Mac

Mon Jan 15, 2018 6:39 am Post

That looks promising, but when I tried it, it didn't work. (And yes, I applied it to an underline in the body, not the TOC.)

Inspired by your illustration, I'd like to check my new mobi file's HTML. But it appears to be a binary file. What tool did you use to reveal the mobi's HTML?

User avatar
nontroppo
Posts: 1067
Joined: Mon Mar 05, 2007 5:22 pm
Platform: Mac
Location: Airstrip One

Mon Jan 15, 2018 9:32 am Post

EPub/Mobi are zip files, so yes technically binary so you can either unzip them first or use Calibre: https://calibre-ebook.com/about that can edit them directly (including a comprehensive HTML+CSS debugging environment). Scrivener also allows you to "Save source files..." in the compiler for both kindle and EPub, which gives an uncompressed version to play with directly...
Screen Shot 2018-01-15 at 17.31.39_SMALL.png
Screen Shot 2018-01-15 at 17.31.39_SMALL.png (12.3 KiB) Viewed 1995 times

bo
bostonquad
Posts: 41
Joined: Tue Nov 28, 2017 7:12 pm
Platform: Mac

Thu Jan 18, 2018 4:03 am Post

First, thank you, nontroppo, I've learned a lot from you. If you're in the Boulder CO area I'll buy you dinner!

I'm so close... I can at least fix it manually, but I don't have it automated yet. Here's what I've learned:

1. ✅Using a character style + assigned prefix/postfix generates the expected XHTML file:
Screen Shot 2018-01-17 at 7.00.10 PM.png
So far so good...
Screen Shot 2018-01-17 at 7.00.10 PM.png (32.79 KiB) Viewed 1948 times


2. ❌ I couldn't see how to check the .mobi directly in Calibre, but I had Calibre convert it to .azw3 so I could check that source. When I did, I found the <mbp:nu> tag had been converted to <nu>! :(
Screen Shot 2018-01-17 at 7.02.07 PM.png
Why did the tag get truncated?
Screen Shot 2018-01-17 at 7.02.07 PM.png (36.88 KiB) Viewed 1948 times


3. ❌ I manually edited the source (hooray for this Calibre ability) back to what it should be... and I still did not get the desired result on Kindle. (I'm testing the .azw3 file in my Mac Kindle app; I can't send it to my Kindle.)

4. ✅ I did several experiments, and found Kindle respects the text-decoration decorative if it is inline, but not if it's in the CSS file (even if it is marked with !important).
Screen Shot 2018-01-17 at 7.25.12 PM.png
This works!
Screen Shot 2018-01-17 at 7.25.12 PM.png (52.25 KiB) Viewed 1948 times


5. :shock: Further experimentation shows the only thing that matters is inlining "text-decoration: none" with the anchor tag; the <mbp:nu> tag seems to not matter!

So... I don't suppose there's a way to get Scrivener to generate that directive inside the anchor tags? (I can get Scrivener to generate <mbp:nu style="text-decoration: none !important;">, but that doesn't work either.)

User avatar
nontroppo
Posts: 1067
Joined: Mon Mar 05, 2007 5:22 pm
Platform: Mac
Location: Airstrip One

Thu Jan 18, 2018 5:35 am Post

Yikes, so close and yet... :lol:

To use Calibre to inspect .mobi, open the mobi in the calibre ebook-viewer, then right click the section of interest and "Inspect" (it isn't the full editor, but does let you peek at the code, and manipulate it in real time just not save the change back to the mobi)...

I do not know of a way to add inline style properties to links generated with Scrivener, all I could suggest is you could make a small script to automatically edit the source HTML generated by Scrivener then compile them using kindlegen.

bo
bostonquad
Posts: 41
Joined: Tue Nov 28, 2017 7:12 pm
Platform: Mac

Fri Jan 19, 2018 2:32 am Post

Ah, thanks... nice to see how to inspect a mobi file -- and I'm on board with the script part.
It's not automatic, but I now know how to get what I want with a little effort.
Thanks for all your help in this thread.