View Single Post
Old 11-15-2019, 03:45 PM   #446
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,932
Karma: 6361444
Join Date: Nov 2009
Device: many
Yes, the new interface offers just such a function:


# returns the href relative path from source bookpath to the target bookpath
#
def get_relativepath(self, from_bookpath, to_bookpath)

So bk.get_relativepath(from_bookpath, to_bookpath)

will nicely create for you the href to reference the to_bookpath file from the "from_bookpath" file. You still need to deal with any fragments afterwards and of course url encode it before writing it to a file.

There are examples of this and routines to help in hrefutils.py as well as that is what the plugin wrapper itself uses.

If you want sample code that builds links to an image file from an html file that is backwards compatible with older versions of Sigil check out ePub3-itizer, and Access-Aide for many examples.
KevinH is offline   Reply With Quote