epub converter: add internal links processing3

This commit is contained in:
shirshasa
2021-05-27 12:15:48 +03:00
parent 836e2dbc11
commit ab7a944bfb

View File

@@ -242,22 +242,18 @@ class EpubPostprocessor:
# if anchor is found we could add placeholder for link creation on server side. # if anchor is found we could add placeholder for link creation on server side.
internal_link_tag.attrs['placeholder'] = '{{tempStyleToAnchor-' + new_id + '}}' internal_link_tag.attrs['placeholder'] = '{{tempStyleToAnchor-' + new_id + '}}'
# create span to have cyclic links, link has 1 type of class, anchor another # create span to have cyclic links, link has 1 type of class, anchor another
if anchor_tag.name == 'a': new_anchor_already_created = soup.find_all('span',
new_anchor_already_created = soup.find_all('span', attrs={'class': 'link-anchor',
attrs={'class': 'link-anchor', 'id': anchor_tag.attrs['id']})
'id': anchor_tag.attrs['id']}) if not new_anchor_already_created:
if not new_anchor_already_created: new_anchor_span = soup.new_tag("span")
new_anchor_span = soup.new_tag("span") new_anchor_span.attrs['id'] = anchor_tag.attrs['id']
new_anchor_span.attrs['id'] = anchor_tag.attrs['id'] new_anchor_span.attrs['class'] = 'link-anchor'
new_anchor_span.attrs['class'] = 'link-anchor' anchor_tag.insert(0, new_anchor_span)
anchor_tag.insert(0, new_anchor_span) del anchor_tag.attrs['id']
del anchor_tag.attrs['id'] self.internal_anchors.add(new_anchor_span)
self.internal_anchors.add(new_anchor_span)
else:
self.internal_anchors.add(anchor_tag)
anchor_tag.attrs['class'] = 'link-anchor'
del internal_link_tag.attrs['href'] del internal_link_tag.attrs['href']
else: else:
internal_link_tag.attrs['converter-mark'] = 'bad-link' internal_link_tag.attrs['converter-mark'] = 'bad-link'