Update barrons.recipe

fix for multiple hyperlinks
This commit is contained in:
unkn0w7n 2025-02-10 10:08:51 +05:30
parent 249052d6e7
commit d9c02b3238

View File

@ -9,24 +9,25 @@ from calibre.web.feeds.news import BasicNewsRecipe
def make_hlinks(zx):
txt = zx['body']['text']
otxt = zx['body']['text']
txt = otxt
if zx['body'].get('additions'):
for ad in zx['body']['additions']:
if ad.get('type', '') == 'link':
strt = ad['rangeStart']
end = ad['rangeLength']
n_txt = txt[strt : (strt + end)]
n_txt = otxt[strt : (strt + end)]
lnk = ad['value']
lnk_txt = f'<a href="{lnk}">{n_txt}</a>'
txt = txt[:strt] + lnk_txt + txt[(strt + end) :]
txt = txt.replace(n_txt, lnk_txt)
if zx['body'].get('inlineTextStyles'):
for sty in zx['body']['inlineTextStyles']:
if 'Italic' in sty['textStyle']['fontName']:
estrt = sty['rangeStart']
eend = sty['rangeLength']
etxt = txt[estrt : (estrt + eend)]
etxt = otxt[estrt : (estrt + eend)]
em_txt = f'<em>{etxt}</em>'
txt = txt[:estrt] + em_txt + txt[(estrt + eend) :]
txt = txt.replace(etxt, em_txt)
return txt