diff --git a/bookmarks/services/exporter.py b/bookmarks/services/exporter.py index fcc775d..1bdff35 100644 --- a/bookmarks/services/exporter.py +++ b/bookmarks/services/exporter.py @@ -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'
{title}') + doc.append( + f'
{title}') if desc: doc.append(f'
{desc}') diff --git a/bookmarks/services/importer.py b/bookmarks/services/importer.py index f130dfa..abffd82 100644 --- a/bookmarks/services/importer.py +++ b/bookmarks/services/importer.py @@ -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 diff --git a/bookmarks/services/parser.py b/bookmarks/services/parser.py index b757507..61bafc4 100644 --- a/bookmarks/services/parser.py +++ b/bookmarks/services/parser.py @@ -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 = '' diff --git a/bookmarks/tests/test_exporter.py b/bookmarks/tests/test_exporter.py index 74f7b06..8e6b7aa 100644 --- a/bookmarks/tests/test_exporter.py +++ b/bookmarks/tests/test_exporter.py @@ -18,7 +18,10 @@ class ExporterTestCase(TestCase, BookmarkFactoryMixin): self.setup_tag(name='tag3')]), self.setup_bookmark(url='https://example.com/3', title='Title 3', added=added, unread=True), self.setup_bookmark(url='https://example.com/4', title='Title 4', added=added, shared=True), - + self.setup_bookmark(url='https://example.com/5', title='Title 5', added=added, shared=True, + description='Example description', notes='Example notes'), + self.setup_bookmark(url='https://example.com/6', title='Title 6', added=added, shared=True, + notes='Example notes'), ] html = exporter.export_netscape_html(bookmarks) @@ -28,13 +31,18 @@ class ExporterTestCase(TestCase, BookmarkFactoryMixin): f'
Title 2', f'
Title 3', f'
Title 4', + f'
Title 5', + '
Example description[linkding-notes]Example notes[/linkding-notes]', + f'
Title 6', + '
[linkding-notes]Example notes[/linkding-notes]', ] self.assertIn('\n\r'.join(lines), html) - def test_escape_html_in_title_and_description(self): + def test_escape_html(self): bookmark = self.setup_bookmark( title='