Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jarun#807] fixed import in single-parent-folder-tag mode #814

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this comment (since it was merely quoting the line immediately before it)

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]):
Copy link
Collaborator Author

@LeXofLeviafan LeXofLeviafan Jan 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the else: branch and modified this line in the if: branch (thus ensuring the same code is used for both import-parents-as-tags modes)

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),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corresponds to a snippet (below) that matches the usecase in question

    <DT><H3>Folder12</H3><DL><p>
        <DT><H3>Folder121</H3><DL><p>
            <DT><A HREF="http://example121.com"></A></DT>
        </DL><p></DT>
        <DT><A HREF="http://example12.com"></A></DT>

("http://example13.com", None, ",folder13 (blah blah),tag3,tag4,", None, 0, True, False),
],
),
Expand Down