Add support for exporting/importing bookmark notes (#532)

This commit is contained in:
Sascha Ißbrücker
2023-09-10 23:37:37 +02:00
committed by GitHub
parent ffcc40b227
commit 28acf3299c
6 changed files with 139 additions and 7 deletions

View File

@@ -31,12 +31,15 @@ def append_bookmark(doc: BookmarkDocument, bookmark: Bookmark):
url = bookmark.url
title = html.escape(bookmark.resolved_title or '')
desc = html.escape(bookmark.resolved_description or '')
if bookmark.notes:
desc += f'[linkding-notes]{html.escape(bookmark.notes)}[/linkding-notes]'
tags = ','.join(bookmark.tag_names)
toread = '1' if bookmark.unread else '0'
private = '0' if bookmark.shared else '1'
added = int(bookmark.date_added.timestamp())
doc.append(f'<DT><A HREF="{url}" ADD_DATE="{added}" PRIVATE="{private}" TOREAD="{toread}" TAGS="{tags}">{title}</A>')
doc.append(
f'<DT><A HREF="{url}" ADD_DATE="{added}" PRIVATE="{private}" TOREAD="{toread}" TAGS="{tags}">{title}</A>')
if desc:
doc.append(f'<DD>{desc}')

View File

@@ -168,6 +168,7 @@ def _import_batch(netscape_bookmarks: List[NetscapeBookmark],
'shared',
'title',
'description',
'notes',
'owner'])
# Bulk insert new bookmarks into DB
Bookmark.objects.bulk_create(bookmarks_to_create)
@@ -214,5 +215,7 @@ def _copy_bookmark_data(netscape_bookmark: NetscapeBookmark, bookmark: Bookmark,
bookmark.title = netscape_bookmark.title
if netscape_bookmark.description:
bookmark.description = netscape_bookmark.description
if netscape_bookmark.notes:
bookmark.notes = netscape_bookmark.notes
if options.map_private_flag and not netscape_bookmark.private:
bookmark.shared = True

View File

@@ -8,6 +8,7 @@ class NetscapeBookmark:
href: str
title: str
description: str
notes: str
date_added: str
tag_string: str
to_read: bool
@@ -26,6 +27,7 @@ class BookmarkParser(HTMLParser):
self.tags = ''
self.title = ''
self.description = ''
self.notes = ''
self.toread = ''
self.private = ''
@@ -58,6 +60,7 @@ class BookmarkParser(HTMLParser):
href=self.href,
title='',
description='',
notes='',
date_added=self.add_date,
tag_string=self.tags,
to_read=self.toread == '1',
@@ -69,12 +72,16 @@ class BookmarkParser(HTMLParser):
self.title = data.strip()
def handle_dd_data(self, data):
self.description = data.strip()
desc = data.strip()
if '[linkding-notes]' in desc:
self.notes = desc.split('[linkding-notes]')[1].split('[/linkding-notes]')[0]
self.description = desc.split('[linkding-notes]')[0]
def add_bookmark(self):
if self.bookmark:
self.bookmark.title = self.title
self.bookmark.description = self.description
self.bookmark.notes = self.notes
self.bookmarks.append(self.bookmark)
self.bookmark = None
self.href = ''
@@ -82,6 +89,7 @@ class BookmarkParser(HTMLParser):
self.tags = ''
self.title = ''
self.description = ''
self.notes = ''
self.toread = ''
self.private = ''