mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make lifting of props more robust, ignoring styles on empty children and also removing empty anchor tags before lifting
This commit is contained in:
parent
a548dcb2c7
commit
ffa7ea75ee
@ -55,10 +55,12 @@ def lift_styles(tag, style_map):
|
|||||||
has_text = bool(tag.text)
|
has_text = bool(tag.text)
|
||||||
child_styles = []
|
child_styles = []
|
||||||
for child in tag.iterchildren('*'):
|
for child in tag.iterchildren('*'):
|
||||||
if child.tail:
|
if child.tail and child.tail.strip():
|
||||||
has_text = True
|
has_text = True
|
||||||
style = style_map[child]
|
style = style_map[child]
|
||||||
child_styles.append(style)
|
child_styles.append(style)
|
||||||
|
if not child.text and len(child) == 0:
|
||||||
|
continue
|
||||||
if common_props is None:
|
if common_props is None:
|
||||||
common_props = style.copy()
|
common_props = style.copy()
|
||||||
else:
|
else:
|
||||||
@ -75,7 +77,7 @@ def lift_styles(tag, style_map):
|
|||||||
if lifted_props:
|
if lifted_props:
|
||||||
for style in child_styles:
|
for style in child_styles:
|
||||||
for k in lifted_props:
|
for k in lifted_props:
|
||||||
del style[k]
|
style.pop(k, None)
|
||||||
|
|
||||||
|
|
||||||
def filter_qt_styles(style):
|
def filter_qt_styles(style):
|
||||||
@ -183,6 +185,7 @@ def cleanup_qt_markup(root):
|
|||||||
style_map = defaultdict(dict)
|
style_map = defaultdict(dict)
|
||||||
for tag in root.xpath('//*[@style]'):
|
for tag in root.xpath('//*[@style]'):
|
||||||
style_map[tag] = parse_style(tag.get('style'))
|
style_map[tag] = parse_style(tag.get('style'))
|
||||||
|
convert_anchors_to_ids(root)
|
||||||
block_tags = root.xpath('//body/*')
|
block_tags = root.xpath('//body/*')
|
||||||
for tag in block_tags:
|
for tag in block_tags:
|
||||||
lift_styles(tag, style_map)
|
lift_styles(tag, style_map)
|
||||||
@ -218,7 +221,6 @@ def cleanup_qt_markup(root):
|
|||||||
lift(span)
|
lift(span)
|
||||||
|
|
||||||
merge_contiguous_links(root)
|
merge_contiguous_links(root)
|
||||||
convert_anchors_to_ids(root)
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user