mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-11 09:13:57 -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):
|
def parse_txt(ty):
|
||||||
typ = ty.get('type', '')
|
typ = ty.get('type', '')
|
||||||
children = ty.get('children', [])
|
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 = {
|
tag_map = {
|
||||||
'text': lambda: [ty.get('value', '')],
|
'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],
|
'italic': lambda: [f'<i>{"".join(parse_txt(c))}</i>' for c in children],
|
||||||
'linebreak': lambda: ['<br>'],
|
'linebreak': lambda: ['<br>'],
|
||||||
'external_link': lambda: [
|
'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
|
if children
|
||||||
else [],
|
else [],
|
||||||
'internal_link': lambda: [
|
'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
|
if children
|
||||||
else [],
|
else [],
|
||||||
|
@ -44,7 +44,12 @@ def process_info_box(bx):
|
|||||||
def parse_txt(ty):
|
def parse_txt(ty):
|
||||||
typ = ty.get('type', '')
|
typ = ty.get('type', '')
|
||||||
children = ty.get('children', [])
|
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 = {
|
tag_map = {
|
||||||
'text': lambda: [ty.get('value', '')],
|
'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],
|
'italic': lambda: [f'<i>{"".join(parse_txt(c))}</i>' for c in children],
|
||||||
'linebreak': lambda: ['<br>'],
|
'linebreak': lambda: ['<br>'],
|
||||||
'external_link': lambda: [
|
'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
|
if children
|
||||||
else [],
|
else [],
|
||||||
'internal_link': lambda: [
|
'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
|
if children
|
||||||
else [],
|
else [],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user