From 0eadcc535f31323a566bd0dc045463c4d3c13934 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Tue, 22 Sep 2020 22:42:45 -0700 Subject: [PATCH] Fix #434 by handling links with titles --- openlp/plugins/bibles/lib/importers/wordproject.py | 9 +++++++-- tests/resources/bibles/wordproject_index.htm | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/bibles/lib/importers/wordproject.py b/openlp/plugins/bibles/lib/importers/wordproject.py index 2e9a96a0a..d14ea2c4f 100644 --- a/openlp/plugins/bibles/lib/importers/wordproject.py +++ b/openlp/plugins/bibles/lib/importers/wordproject.py @@ -83,12 +83,17 @@ class WordProjectBible(BibleImport): log.debug(li_book) if self.stop_import_flag: break - # Sometimes the structure is "[1] Genesis", and sometimes it's "[1] Genesis" if isinstance(li_book.contents[0], NavigableString) and str(li_book.contents[0]).strip(): + # Sometimes the structure is "[1] Genesis", and sometimes it's "[1] Genesis" book_string = str(li_book.contents[0]) book_name = str(li_book.a.contents[0]) - elif li_book.a: + elif li_book.a and ']' in li_book.a.contents[0]: + # Sometimes there is a [1] in the link text book_string, book_name = str(li_book.a.contents[0]).split(' ', 1) + elif li_book.a and 'title' in li_book.a.attrs: + # And sometimes there's a title on the a with the number in it + book_string = li_book.a['title'].split(' ')[0] + book_name = li_book.a.contents[0].strip() book_link = li_book.a['href'] book_id = int(BOOK_NUMBER_PATTERN.search(book_string).group(1)) book_name = book_name.strip() diff --git a/tests/resources/bibles/wordproject_index.htm b/tests/resources/bibles/wordproject_index.htm index 861ca2dda..bb99c0040 100644 --- a/tests/resources/bibles/wordproject_index.htm +++ b/tests/resources/bibles/wordproject_index.htm @@ -107,11 +107,11 @@

Old Testament