mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-07 09:01:38 -04:00
economist: fix parsing of <a> tags with multiple attributes
This commit is contained in:
parent
c4f2311ba7
commit
e9c1216ded
@ -44,7 +44,12 @@ def process_info_box(bx):
|
||||
def parse_txt(ty):
|
||||
typ = ty.get('type', '')
|
||||
children = ty.get('children', [])
|
||||
attr = ty.get('attributes', [{}])[0].get('value', '#')
|
||||
href = '#'
|
||||
attributes = ty.get('attributes') or ()
|
||||
for a in attributes:
|
||||
if a.get('name') == 'href':
|
||||
href = a.get('value', href)
|
||||
break
|
||||
|
||||
tag_map = {
|
||||
'text': lambda: [ty.get('value', '')],
|
||||
@ -57,12 +62,12 @@ def parse_txt(ty):
|
||||
'italic': lambda: [f'<i>{"".join(parse_txt(c))}</i>' for c in children],
|
||||
'linebreak': lambda: ['<br>'],
|
||||
'external_link': lambda: [
|
||||
f'<a href="{attr}">{"".join(parse_txt(children[0]))}</a>'
|
||||
f'<a href="{href}">{"".join(parse_txt(children[0]))}</a>'
|
||||
]
|
||||
if children
|
||||
else [],
|
||||
'internal_link': lambda: [
|
||||
f'<a href="{attr}">{"".join(parse_txt(children[0]))}</a>'
|
||||
f'<a href="{href}">{"".join(parse_txt(children[0]))}</a>'
|
||||
]
|
||||
if children
|
||||
else [],
|
||||
|
@ -44,7 +44,12 @@ def process_info_box(bx):
|
||||
def parse_txt(ty):
|
||||
typ = ty.get('type', '')
|
||||
children = ty.get('children', [])
|
||||
attr = ty.get('attributes', [{}])[0].get('value', '#')
|
||||
href = '#'
|
||||
attributes = ty.get('attributes') or ()
|
||||
for a in attributes:
|
||||
if a.get('name') == 'href':
|
||||
href = a.get('value', href)
|
||||
break
|
||||
|
||||
tag_map = {
|
||||
'text': lambda: [ty.get('value', '')],
|
||||
@ -57,12 +62,12 @@ def parse_txt(ty):
|
||||
'italic': lambda: [f'<i>{"".join(parse_txt(c))}</i>' for c in children],
|
||||
'linebreak': lambda: ['<br>'],
|
||||
'external_link': lambda: [
|
||||
f'<a href="{attr}">{"".join(parse_txt(children[0]))}</a>'
|
||||
f'<a href="{href}">{"".join(parse_txt(children[0]))}</a>'
|
||||
]
|
||||
if children
|
||||
else [],
|
||||
'internal_link': lambda: [
|
||||
f'<a href="{attr}">{"".join(parse_txt(children[0]))}</a>'
|
||||
f'<a href="{href}">{"".join(parse_txt(children[0]))}</a>'
|
||||
]
|
||||
if children
|
||||
else [],
|
||||
|
Loading…
x
Reference in New Issue
Block a user