Skip to content

Commit

Permalink
[jarun#807] fixed import in single-parent-folder-tag mode
Browse files Browse the repository at this point in the history
  • Loading branch information
LeXofLeviafan committed Jan 19, 2025
1 parent 2bd94b1 commit c31c6bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
40 changes: 13 additions & 27 deletions buku
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_buku.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
),
Expand Down

0 comments on commit c31c6bf

Please sign in to comment.