From c31c6bf99369ed98148a6ae42ca320a1d928f28d Mon Sep 17 00:00:00 2001 From: LeXofLeviafan Date: Sun, 19 Jan 2025 09:39:41 +0100 Subject: [PATCH] [jarun#807] fixed import in single-parent-folder-tag mode --- buku | 40 +++++++++++++--------------------------- tests/test_buku.py | 2 +- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/buku b/buku index 41a8214f..13ae46f9 100755 --- a/buku +++ b/buku @@ -4014,35 +4014,21 @@ def import_html(html_soup: BeautifulSoup, add_parent_folder_as_tag: bool, newtag desc = comment_tag.find(string=True, recursive=False) if add_parent_folder_as_tag: - # add parent folder as tag - if use_nested_folder_structure: - # New method that would generalize for else case to - # structure of folders - # dt - # h3 (folder name) - # dl - # dt - # a (could be h3, and continue recursively) - parents = tag.find_parents('dl') - for parent in parents: - header = parent.find_previous_sibling('h3') - if header: - if tag.has_attr('tags'): - tag['tags'] += (DELIM + strip_delim(header.text)) - else: - tag['tags'] = strip_delim(header.text) - else: - # could be its folder or not - possible_folder = tag.find_previous('h3') - # get list of tags within that folder - tag_list = tag.parent.parent.find_parent('dl') - - if ((possible_folder) and possible_folder.parent in list(tag_list.parents)): - # then it's the folder of this bookmark + # New method that would generalize for else case to + # structure of folders + # dt + # h3 (folder name) + # dl + # dt + # a (could be h3, and continue recursively) + parents = tag.find_parents('dl') + for parent in (parents if use_nested_folder_structure else parents[:1]): + header = parent.find_previous_sibling('h3') + if header: if tag.has_attr('tags'): - tag['tags'] += (DELIM + strip_delim(possible_folder.text)) + tag['tags'] += (DELIM + strip_delim(header.text)) else: - tag['tags'] = strip_delim(possible_folder.text) + tag['tags'] = strip_delim(header.text) # add unique tag if opted if newtag: diff --git a/tests/test_buku.py b/tests/test_buku.py index e5badc73..e0259d0a 100644 --- a/tests/test_buku.py +++ b/tests/test_buku.py @@ -791,7 +791,7 @@ def test_import_html_and_add_parent(): [ ("http://example11.com", None, ",folder11,", None, 0, True, False), ("http://example121.com", None, ",folder121,", None, 0, True, False), - ("http://example12.com", None, None, None, 0, True, False), + ("http://example12.com", None, ",folder12,", None, 0, True, False), ("http://example13.com", None, ",folder13 (blah blah),tag3,tag4,", None, 0, True, False), ], ),