From 2429c45a7e3b8e3ef24794b9c982ffcf121acdbd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Robert=20B=C5=82aut?= Date: Wed, 29 Jan 2014 12:31:53 +0100 Subject: [PATCH 1/1] [epub, mobi] Fix for a problem with epubs, mobi in drama ebooks without acts Better aproach than previous one. --- librarian/epub.py | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/librarian/epub.py b/librarian/epub.py index 2f7bbec..6a2b3c5 100644 --- a/librarian/epub.py +++ b/librarian/epub.py @@ -291,18 +291,41 @@ def chop(main_text): main_xml_part = part_xml[0] # master last_node_part = False + + # the below loop are workaround for a problem with epubs in drama ebooks without acts + is_scene = False + is_act = False + for one_part in main_text: + name = one_part.tag + if name == 'naglowek_scena': + is_scene = True + elif name == 'naglowek_akt': + is_act = True + for one_part in main_text: name = one_part.tag - if name == 'naglowek_czesc': - yield part_xml - last_node_part = True - main_xml_part[:] = [deepcopy(one_part)] - elif not last_node_part and name in ("naglowek_rozdzial", "naglowek_akt", "srodtytul"): - yield part_xml - main_xml_part[:] = [deepcopy(one_part)] + if is_act is False and is_scene is True: + if name == 'naglowek_czesc': + yield part_xml + last_node_part = True + main_xml_part[:] = [deepcopy(one_part)] + elif not last_node_part and name in ("naglowek_scena"): + yield part_xml + main_xml_part[:] = [deepcopy(one_part)] + else: + main_xml_part.append(deepcopy(one_part)) + last_node_part = False else: - main_xml_part.append(deepcopy(one_part)) - last_node_part = False + if name == 'naglowek_czesc': + yield part_xml + last_node_part = True + main_xml_part[:] = [deepcopy(one_part)] + elif not last_node_part and name in ("naglowek_rozdzial", "naglowek_akt", "srodtytul"): + yield part_xml + main_xml_part[:] = [deepcopy(one_part)] + else: + main_xml_part.append(deepcopy(one_part)) + last_node_part = False yield part_xml -- 2.20.1