Fix copy all book details not respecting line breaks in fields

This commit is contained in:
Kovid Goyal 2023-05-10 07:06:21 +05:30
parent e9a0b5dcf1
commit dcbb72a2b8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -92,6 +92,9 @@ def copy_all(text_browser):
if not is_vertical: if not is_vertical:
parent = tables[1] parent = tables[1]
for tag in parent.iterdescendants('td'): for tag in parent.iterdescendants('td'):
for child in tag.iterdescendants('br'):
child.tag = 'span'
child.text = '\ue000'
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):
@ -105,6 +108,7 @@ def copy_all(text_browser):
from calibre.utils.html2text import html2text from calibre.utils.html2text import html2text
simplified_html = etree.tostring(root, encoding='unicode') simplified_html = etree.tostring(root, encoding='unicode')
txt = html2text(simplified_html, single_line_break=True).strip() txt = html2text(simplified_html, single_line_break=True).strip()
txt = txt.replace('\ue000', '\n\t')
if iswindows: if iswindows:
txt = os.linesep.join(txt.splitlines()) txt = os.linesep.join(txt.splitlines())
# print(simplified_html) # print(simplified_html)