View Single Post
Old 03-13-2011, 04:12 PM   #352
mostlynovels
Member
mostlynovels doesn't littermostlynovels doesn't littermostlynovels doesn't litter
 
Posts: 10
Karma: 228
Join Date: Jan 2011
Location: USA
Device: past: Bookeen (2yrs); present: laptop(WinXP), 3.5"phone(WinMob6.5)
Re: Problem: calibre seems to force color of links

3 CHOICES OF WORKAROUNDS

After a lot of trial and error, learning, and more trial and error:

- It's definite that when converting to mobi, calibre (as of 0.7.45) forces the color of links to the named-color blue, by coding it into the mobi file (via mobi's font element, <font color="blue">...</font> ). This includes the mobi-generated TOC.

- Eventually I trial-and-errored my way to 3 choices of workarounds:
Choice 1. Do an additional conversion, mobi-to-mobi, using calibre.
Choice 2. Edit the mobi file itself.
Choice 3. During calibre's first conversion to mobi.

Each has some cons (described below) but hopefully the choices will at least be good starting points for other people who might want to change/remove the dark blue link color.

If you identify improved/additional workarounds, please post.



****************************************
****************************************

WORKAROUND CHOICE 1
DO AN ADDITIONAL CONVERSION, MOBI-TO-MOBI, USING CALIBRE

- Pros: easy; fast; risk free; minimal learning curve;
- Cons: requires forcing the links to one color (of your choice), preventing the reader from setting it themselves;

1. It's always a good idea to make a backup copy of your original!

2. Decide on the link color you would like. It can be one of the named colors, e.g. aqua, or it can be in the form e.g. #00FFFF . Substitute your desired color for aqua in the Replacement Text in step 3.

3. In calibre's Search & Replace screen
- In the First expression's "Search Regular Expression" box add a regex similar to:

Code:
(<a[^>]*?href[^>]*>[\w\W]*?<font color=")blue(">[\w\W]*?</font>)
- In the First expression's "Replacement Text" box add a replace string similar to:

Code:
\1aqua\2
4. In calibre's MOBI Output screen
- Select "Do not add Table of Contents to book" (this WILL leave a mobi-generated TOC that's already there).

NOTE: I did also try a regex+replace that would just eliminate the font element entirely (similar to the one in Choice 2), but it didn't work ... not sure why. Seems like if the above one worked, then one similar to Choice 2 should also.

****************************************

WORKAROUND CHOICE 2
EDIT THE MOBI FILE ITSELF

- Pros: doesn't require forcing the links a new color, allowing the reader to set it themselves;
- Cons: less easy; less fast; has the risks associated with exploding/rebuilding a mobi file; can be time consuming to learn to explode/rebuild mobi files;

1. It's always a good idea to make a backup copy of your original.

2. Explode the mobi file using MobiUnpack or other tool/application (search MR for details).

3. Edit the mobi file with your favorite regex engine that also does replace (standalone or part of a text editor).
- Can remove the named-color blue from the links, or if prefered can force it to a color of your choice.
- To remove the named-color blue from the links, use search & replace similar to:

Code:
Search:  (<a[^>]*?href[^>]*>[\w\W]*?)<font color="blue">([\w\W]*?)</font>
Replace: $1$2
- To instead change the named-color blue of the links to another color:

- Decide on the link color you would like. It can be one of the named colors, e.g. aqua, or it can be in the form e.g. #00FFFF . Substitute your desired color for aqua in the below Replace text.

- Use search & replace similar to:

Code:
Search:  (<a[^>]*?href[^>]*>[\w\W]*?<font color=")blue(">[\w\W]*?</font>)
Replace: $1aqua$2
4. Rebuild the mobi file using Kindlegen or other tool/application (search MR for details).

****************************************

WORKAROUND CHOICE 3
DURING CALIBRE'S FIRST CONVERSION TO MOBI

- This is based on using a higher specificity selector, as Kovid suggested.

- Pros: easy; fast; risk free; minimal learning curve; no additional conversions/editing required;
- Cons: doesn't change the dark-blue color of mobi-generated TOCs; requires forcing the links to one color (of your choice), preventing the reader from setting it themselves;

1. It's always a good idea to make a backup copy of your original!

2. Decide on the link color you would like. It can be one of the named colors, e.g. aqua, or it can be in the form e.g. #00FFFF. Substitute your desired color for aqua in the CSS in step 3.

3. In calibre's Look & Feel screen
- In the Extra CSS box add CSS similar to:

Code:
.lnk_txt {
color: aqua !important;
text-decoration: underline !important;
}
4. In calibre's Search & Replace screen
- In the First expression's Search "Regular Expression" box add a regex similar to:

Code:
(<a[^>]*?href[^>]*>)([\w\W]*?)(</a>)
- In the First expression's "Replacement Text" box add a replace string similar to:

Code:
\1<span class="lnk_txt">\2</span>\3
****************************************
mostlynovels is offline   Reply With Quote