1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
import { describe, expect, it } from "vitest";
import { parseImportFile } from "./parsers";
describe("parseNetscapeBookmarkFile", () => {
it("parses a simple bookmark file with single bookmark", () => {
const html = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
<DT><A HREF="https://example.com" ADD_DATE="1234567890">Example Site</A>
</DL><p>`;
const result = parseImportFile("html", html);
expect(result).toHaveLength(1);
expect(result[0]).toMatchObject({
title: "Example Site",
content: {
type: "link",
url: "https://example.com",
},
tags: [],
addDate: 1234567890,
paths: [[]],
});
});
it("parses bookmarks with tags", () => {
const html = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
<DT><A HREF="https://example.com" ADD_DATE="1234567890" TAGS="tag1,tag2,tag3">Example Site</A>
</DL><p>`;
const result = parseImportFile("html", html);
expect(result).toHaveLength(1);
expect(result[0].tags).toEqual(["tag1", "tag2", "tag3"]);
});
it("parses bookmarks in nested folders", () => {
const html = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
<DT><H3 ADD_DATE="1234567890" LAST_MODIFIED="1234567891">Folder1</H3>
<DL><p>
<DT><H3 ADD_DATE="1234567892" LAST_MODIFIED="1234567893">Folder2</H3>
<DL><p>
<DT><A HREF="https://example.com" ADD_DATE="1234567894">Nested Bookmark</A>
</DL><p>
</DL><p>
</DL><p>`;
const result = parseImportFile("html", html);
expect(result).toHaveLength(1);
expect(result[0]).toMatchObject({
title: "Nested Bookmark",
content: {
type: "link",
url: "https://example.com",
},
paths: [["Folder1", "Folder2"]],
});
});
it("handles empty folder names by replacing with 'Unnamed'", () => {
const html = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
<DT><H3 ADD_DATE="1234567890" LAST_MODIFIED="1234567891">Named Folder</H3>
<DL><p>
<DT><H3 ADD_DATE="1234567892" LAST_MODIFIED="0"></H3>
<DL><p>
<DT><A HREF="https://example.com" ADD_DATE="1234567894">Bookmark</A>
</DL><p>
</DL><p>
</DL><p>`;
const result = parseImportFile("html", html);
expect(result).toHaveLength(1);
expect(result[0].paths).toEqual([["Named Folder", "Unnamed"]]);
});
it("parses multiple bookmarks in different folders", () => {
const html = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
<DT><H3 ADD_DATE="1234567890">Tech</H3>
<DL><p>
<DT><A HREF="https://github.com" ADD_DATE="1234567891">GitHub</A>
<DT><A HREF="https://stackoverflow.com" ADD_DATE="1234567892">Stack Overflow</A>
</DL><p>
<DT><H3 ADD_DATE="1234567893">News</H3>
<DL><p>
<DT><A HREF="https://news.ycombinator.com" ADD_DATE="1234567894">Hacker News</A>
</DL><p>
</DL><p>`;
const result = parseImportFile("html", html);
expect(result).toHaveLength(3);
expect(result[0]).toMatchObject({
title: "GitHub",
content: { type: "link", url: "https://github.com" },
paths: [["Tech"]],
});
expect(result[1]).toMatchObject({
title: "Stack Overflow",
content: { type: "link", url: "https://stackoverflow.com" },
paths: [["Tech"]],
});
expect(result[2]).toMatchObject({
title: "Hacker News",
content: { type: "link", url: "https://news.ycombinator.com" },
paths: [["News"]],
});
});
it("parses bookmarks at root level (no folders)", () => {
const html = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
<DT><A HREF="https://example1.com" ADD_DATE="1234567890">Bookmark 1</A>
<DT><A HREF="https://example2.com" ADD_DATE="1234567891">Bookmark 2</A>
</DL><p>`;
const result = parseImportFile("html", html);
expect(result).toHaveLength(2);
expect(result[0].paths).toEqual([[]]);
expect(result[1].paths).toEqual([[]]);
});
it("handles deeply nested folder structures", () => {
const html = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
<DT><H3>Level1</H3>
<DL><p>
<DT><H3>Level2</H3>
<DL><p>
<DT><H3>Level3</H3>
<DL><p>
<DT><H3>Level4</H3>
<DL><p>
<DT><A HREF="https://example.com" ADD_DATE="1234567890">Deep Bookmark</A>
</DL><p>
</DL><p>
</DL><p>
</DL><p>
</DL><p>`;
const result = parseImportFile("html", html);
expect(result).toHaveLength(1);
expect(result[0].paths).toEqual([["Level1", "Level2", "Level3", "Level4"]]);
});
it("deduplicates bookmarks with the same URL", () => {
const html = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
<DT><H3>Folder1</H3>
<DL><p>
<DT><A HREF="https://example.com" ADD_DATE="1234567890" TAGS="tag1">First Instance</A>
</DL><p>
<DT><H3>Folder2</H3>
<DL><p>
<DT><A HREF="https://example.com" ADD_DATE="1234567891" TAGS="tag2">Second Instance</A>
</DL><p>
</DL><p>`;
const result = parseImportFile("html", html);
expect(result).toHaveLength(1);
expect(result[0]).toMatchObject({
content: { type: "link", url: "https://example.com" },
tags: ["tag1", "tag2"],
addDate: 1234567890, // Should keep the earlier date
});
expect(result[0].paths).toHaveLength(2);
expect(result[0].paths).toContainEqual(["Folder1"]);
expect(result[0].paths).toContainEqual(["Folder2"]);
});
it("merges notes from duplicate bookmarks", () => {
const html = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
<DT><A HREF="https://example.com" ADD_DATE="1234567890">Bookmark</A>
<DD>First note
<DT><A HREF="https://example.com" ADD_DATE="1234567891">Bookmark</A>
<DD>Second note
</DL><p>`;
// Note: The current parser doesn't extract DD notes, but this test
// documents the expected behavior if/when DD parsing is added
const result = parseImportFile("html", html);
expect(result).toHaveLength(1);
expect(result[0].content).toMatchObject({
type: "link",
url: "https://example.com",
});
});
it("handles bookmarks without ADD_DATE attribute", () => {
const html = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
<DT><A HREF="https://example.com">No Date Bookmark</A>
</DL><p>`;
const result = parseImportFile("html", html);
expect(result).toHaveLength(1);
expect(result[0].addDate).toBeUndefined();
});
it("handles bookmarks without HREF attribute", () => {
const html = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
<DT><A ADD_DATE="1234567890">No URL Bookmark</A>
</DL><p>`;
const result = parseImportFile("html", html);
expect(result).toHaveLength(1);
expect(result[0].content).toBeUndefined();
});
it("handles mixed structure with folders and root-level bookmarks", () => {
const html = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
<DT><A HREF="https://root1.com" ADD_DATE="1234567890">Root Bookmark 1</A>
<DT><H3>Folder</H3>
<DL><p>
<DT><A HREF="https://folder1.com" ADD_DATE="1234567891">Folder Bookmark</A>
</DL><p>
<DT><A HREF="https://root2.com" ADD_DATE="1234567892">Root Bookmark 2</A>
</DL><p>`;
const result = parseImportFile("html", html);
expect(result).toHaveLength(3);
expect(result[0]).toMatchObject({
title: "Root Bookmark 1",
paths: [[]],
});
expect(result[1]).toMatchObject({
title: "Folder Bookmark",
paths: [["Folder"]],
});
expect(result[2]).toMatchObject({
title: "Root Bookmark 2",
paths: [[]],
});
});
it("throws error for non-Netscape bookmark files", () => {
const html = `<html>
<head><title>Not a bookmark file</title></head>
<body>Just a regular HTML file</body>
</html>`;
expect(() => parseImportFile("html", html)).toThrow(
"The uploaded html file does not seem to be a bookmark file",
);
});
});
|