View Single Post
Old 04-01-2023, 04:04 PM   #554
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,471
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by isarl View Post
(At first I thought the Calibre template function to_hex() might be useful, but it hex-encodes the entire string, and without the “%” character. Not really what we want here.)
Actually, to_hex() is exactly what you want. If you use it then you don't do any url encoding.

Libraries that are hex encoded must start with '_hex_-'.

Here is an example of building a calibre:// url using the function.
Code:
program:
	lib = 'library.test_small';
	hex_lib = '_hex_-' & to_hex(lib);
	url = 'calibre://book-details/' & hex_lib & '/' & $id;
	'<a href="' & url & '">Book id ' & $id & '</a>'
It produces links that look like
Code:
calibre://book-details/_hex_-6c6962726172792e746573745f736d616c6c/1385
You can also use it for query strings. Instead of q=string, you use eq=hex-encoded-string.

All of this is documented here.
chaley is offline   Reply With Quote