From acf065e4cfb64442eb9c09bad1d5c89ab566f9cf Mon Sep 17 00:00:00 2001 From: unkn0w7n <51942695+unkn0w7n@users.noreply.github.com> Date: Sun, 6 Apr 2025 14:00:29 +0530 Subject: [PATCH] Update barrons.recipe --- recipes/barrons.recipe | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/recipes/barrons.recipe b/recipes/barrons.recipe index f0d182bc42..e23958d88e 100644 --- a/recipes/barrons.recipe +++ b/recipes/barrons.recipe @@ -8,33 +8,30 @@ import re from calibre.web.feeds.news import BasicNewsRecipe +def range(r_, otxt): + return otxt[r_['rangeStart'] : r_['rangeStart'] + r_['rangeLength']] + + def make_hlinks(zx): 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['rangeStart'] + ad['rangeLength'] - n_txt = otxt[strt:end] - lnk = ad.get('value', '') - lnk_txt = f'{n_txt}' - txt = txt.replace(n_txt, lnk_txt) if zx['body'].get('inlineTextStyles'): for sty in zx['body']['inlineTextStyles']: + rtxt = range(sty, otxt) if 'Italic' in sty['textStyle']['fontName']: - estrt = sty['rangeStart'] - eend = sty['rangeStart'] + sty['rangeLength'] - etxt = otxt[estrt:eend] - em_txt = f'{etxt}' - txt = txt.replace(etxt, em_txt) + txt = txt.replace(rtxt, f'{rtxt}') if 'Bold' in sty['textStyle']['fontName']: - bstrt = sty['rangeStart'] - bend = sty['rangeStart'] + sty['rangeLength'] - btxt = otxt[bstrt:bend] - b_txt = f'{btxt}' - txt = txt.replace(btxt, b_txt) - return txt.replace('\n\n', '
{a["body"]["text"]}
' return f'{make_hlinks(a)}
' if typ == 'image': return f'