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', '
').replace('\n', '
') + txt = txt.replace(rtxt, f'{rtxt}') + if sty['textStyle'].get('fontSize', '') == 16: + txt = txt.replace(rtxt, f'{rtxt}') + if zx['body'].get('additions'): + for ad in zx['body']['additions']: + if ad.get('type', '') == 'link' and ad.get('value'): + n_txt = range(ad, otxt) + lnk = ad['value'] + lnk_txt = f'{n_txt}' + txt = txt.replace(n_txt, lnk_txt) + return txt.replace('\n', '
') def make_html(a): @@ -49,6 +46,8 @@ def make_html(a): if typ == 'body': if 'body-h' in a['body'].get('textStyleID', ''): return f'

{a["body"]["text"]}

' + if 'article-summary' in a['body'].get('textStyleID', ''): + return f'

{a["body"]["text"]}

' return f'

{make_hlinks(a)}

' if typ == 'image': return f''