From c42d2db421e7532dd0b3c5711b8c3ba805ef52b3 Mon Sep 17 00:00:00 2001 From: Andrey Efremov Date: Wed, 9 Oct 2019 12:13:25 +0700 Subject: [PATCH] FB2 Output: Handle external links --- src/calibre/ebooks/fb2/fb2ml.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/fb2/fb2ml.py b/src/calibre/ebooks/fb2/fb2ml.py index 197f063baa..7198d0f321 100644 --- a/src/calibre/ebooks/fb2/fb2ml.py +++ b/src/calibre/ebooks/fb2/fb2ml.py @@ -21,12 +21,13 @@ from calibre.utils.img import save_cover_data_to from calibre.ebooks.oeb.base import urlnormalize from polyglot.builtins import unicode_type, string_or_bytes, range, filter from polyglot.binary import as_base64_unicode +from polyglot.urllib import urlparse class FB2MLizer(object): ''' Todo: * Include more FB2 specific tags in the conversion. - * Handle a tags. + * Handle notes and anchor links. ''' def __init__(self, log): @@ -508,6 +509,14 @@ class FB2MLizer(object): fb2_out += p_text if added_p: tags.append('p') + if tag == 'a' and elem_tree.attrib.get('href', None): + # Handle only external links for now + if urlparse(elem_tree.attrib['href']).netloc: + p_txt, p_tag = self.ensure_p() + fb2_out += p_txt + tags += p_tag + fb2_out.append('' % urlnormalize(elem_tree.attrib['href'])) + tags.append('a') if tag == 'b' or style['font-weight'] in ('bold', 'bolder'): s_out, s_tags = self.handle_simple_tag('strong', tag_stack+tags) fb2_out += s_out