mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Book details: Fix formatting of text when copying all book details in narrow mode
This commit is contained in:
parent
dcd5978707
commit
5993dca2f2
@ -84,15 +84,22 @@ def copy_all(text_browser):
|
|||||||
from html5_parser import parse
|
from html5_parser import parse
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
root = parse(html)
|
root = parse(html)
|
||||||
for x in ('table', 'tr', 'tbody'):
|
tables = tuple(root.iterdescendants('table'))
|
||||||
for tag in root.iterdescendants(x):
|
for tag in root.iterdescendants(('table', 'tr', 'tbody')):
|
||||||
tag.tag = 'div'
|
tag.tag = 'div'
|
||||||
for tag in root.iterdescendants('td'):
|
parent = root
|
||||||
|
is_vertical = getattr(text_browser, 'vertical', True)
|
||||||
|
if not is_vertical:
|
||||||
|
parent = tables[1]
|
||||||
|
for tag in parent.iterdescendants('td'):
|
||||||
tt = etree.tostring(tag, method='text', encoding='unicode')
|
tt = etree.tostring(tag, method='text', encoding='unicode')
|
||||||
tag.tag = 'span'
|
tag.tag = 'span'
|
||||||
for child in tuple(tag):
|
for child in tuple(tag):
|
||||||
tag.remove(child)
|
tag.remove(child)
|
||||||
tag.text = tt.strip()
|
tag.text = tt.strip()
|
||||||
|
if not is_vertical:
|
||||||
|
for tag in root.iterdescendants('td'):
|
||||||
|
tag.tag = 'div'
|
||||||
for tag in root.iterdescendants('a'):
|
for tag in root.iterdescendants('a'):
|
||||||
tag.attrib.pop('href', None)
|
tag.attrib.pop('href', None)
|
||||||
from calibre.utils.html2text import html2text
|
from calibre.utils.html2text import html2text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user