From 11abc6ce301341eec5b70b952f2e6308c8fb8a7a Mon Sep 17 00:00:00 2001 From: quantrancse Date: Thu, 26 Aug 2021 00:11:32 +0700 Subject: [PATCH] Fix replace trans note by note id --- hako2epub.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/hako2epub.py b/hako2epub.py index 657ab95..8a52dc8 100644 --- a/hako2epub.py +++ b/hako2epub.py @@ -343,19 +343,18 @@ def make_image(self, chapter_content, chapter_id): return content def get_chapter_content_note(self, soup): - raw_content = soup.find('div', id='chapter-content').text - note_tag_list = re.findall(r'\[note(.*?)\]', raw_content) - note_tag_list = ['[note' + note_id + ']' for note_id in note_tag_list] - note_reg_list = [ - '(Note: ' + note.text + ')' for note in soup.findAll('span', 'note-content_real long-text')] - note_list = list(zip(note_tag_list, note_reg_list)) + note_list = {} + note_div_list = soup.findAll('div', id=re.compile("^note")) + for div in note_div_list: + note_tag = '[' + div.get('id') + ']' + note_reg = '(Note: ' + div.text[10:] + ')' + note_list[note_tag] = note_reg return note_list def replace_chapter_content_note(self, chapter_content, note_list): - for note in note_list: - note_id = note[0] - note_print = note[1] - chapter_content = chapter_content.replace(note_id, note_print) + for note_tag in note_list.keys(): + chapter_content = chapter_content.replace( + note_tag, note_list[note_tag]) return chapter_content def bind_epub_book(self):