netscape-bookmark-parser 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-ja.md +202 -369
- package/README.md +122 -287
- package/esm/src/BookmarksParser/BookmarksParser.d.ts +120 -1
- package/esm/src/BookmarksParser/BookmarksParser.d.ts.map +1 -1
- package/esm/src/BookmarksParser/BookmarksParser.js +129 -2
- package/esm/src/BookmarksTree/BookmarksTree.d.ts +102 -0
- package/esm/src/BookmarksTree/BookmarksTree.d.ts.map +1 -1
- package/esm/src/BookmarksTree/BookmarksTree.js +106 -2
- package/esm/src/web/BookmarksParser/BookmarksParser.d.ts +120 -1
- package/esm/src/web/BookmarksParser/BookmarksParser.d.ts.map +1 -1
- package/esm/src/web/BookmarksParser/BookmarksParser.js +129 -2
- package/esm/src/web/BookmarksTree/BookmarksTree.d.ts +102 -0
- package/esm/src/web/BookmarksTree/BookmarksTree.d.ts.map +1 -1
- package/esm/src/web/BookmarksTree/BookmarksTree.js +106 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
# Netscape Bookmark Parser
|
|
2
2
|
|
|
3
|
-
> **Note:**
|
|
4
|
-
> This README is an AI-generated document. Details are mostly accurate but might include inaccurate description.
|
|
5
|
-
|
|
6
3
|
A TypeScript/JavaScript library for parsing browser bookmark files (HTML format) and manipulating them as structured data. Compatible with both Deno and Node.js runtimes.
|
|
7
4
|
|
|
8
|
-
|
|
5
|
+
> **Note:**
|
|
6
|
+
> This README is an AI-generated document. Details are mostly accurate but might include inaccurate description.
|
|
7
|
+
> 日本語ドキュメント: [`./README-ja.md`](./README-ja.md)
|
|
9
8
|
|
|
10
9
|
## Features
|
|
11
10
|
|
|
@@ -24,6 +23,10 @@ A TypeScript/JavaScript library for parsing browser bookmark files (HTML format)
|
|
|
24
23
|
npm install netscape-bookmark-parser
|
|
25
24
|
```
|
|
26
25
|
|
|
26
|
+
```typescript
|
|
27
|
+
import { BookmarksParser, BookmarksTree } from "netscape-bookmark-parser";
|
|
28
|
+
```
|
|
29
|
+
|
|
27
30
|
### Deno
|
|
28
31
|
|
|
29
32
|
```typescript
|
|
@@ -33,7 +36,7 @@ import {
|
|
|
33
36
|
} from "jsr:@grakeice/netscape-bookmark-parser";
|
|
34
37
|
```
|
|
35
38
|
|
|
36
|
-
> **Note:** The JSR version only includes the Node.js/Deno runtime
|
|
39
|
+
> **Note:** The JSR version only includes the Node.js/Deno runtime. For browser support, please use the npm package.
|
|
37
40
|
|
|
38
41
|
### Browser
|
|
39
42
|
|
|
@@ -60,47 +63,30 @@ function handleFileUpload(event: Event) {
|
|
|
60
63
|
}
|
|
61
64
|
```
|
|
62
65
|
|
|
63
|
-
#### Option 2:
|
|
64
|
-
|
|
65
|
-
```html
|
|
66
|
-
<script type="module">
|
|
67
|
-
import {
|
|
68
|
-
BookmarksParser,
|
|
69
|
-
BookmarksTree,
|
|
70
|
-
} from "./node_modules/netscape-bookmark-parser/esm/mod_web.js";
|
|
71
|
-
|
|
72
|
-
// Your bookmark processing code here...
|
|
73
|
-
</script>
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
#### Option 3: CDN with Import Maps
|
|
66
|
+
#### Option 2: CDN with Import Maps
|
|
77
67
|
|
|
78
68
|
```html
|
|
79
69
|
<script type="importmap">
|
|
80
70
|
{
|
|
81
71
|
"imports": {
|
|
82
|
-
"netscape-bookmark-parser/web": "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.
|
|
72
|
+
"netscape-bookmark-parser/web": "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.4/esm/mod_web.js"
|
|
83
73
|
}
|
|
84
74
|
}
|
|
85
75
|
</script>
|
|
86
76
|
<script type="module">
|
|
87
77
|
import { BookmarksParser, BookmarksTree } from "netscape-bookmark-parser/web";
|
|
88
|
-
|
|
89
|
-
// Works the same as local imports
|
|
90
78
|
const tree = BookmarksParser.parse(htmlContent);
|
|
91
79
|
</script>
|
|
92
80
|
```
|
|
93
81
|
|
|
94
|
-
#### Option
|
|
82
|
+
#### Option 3: Direct CDN Import
|
|
95
83
|
|
|
96
84
|
```html
|
|
97
85
|
<script type="module">
|
|
98
86
|
import {
|
|
99
87
|
BookmarksParser,
|
|
100
88
|
BookmarksTree,
|
|
101
|
-
} from "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.
|
|
102
|
-
|
|
103
|
-
// Direct CDN import without import maps
|
|
89
|
+
} from "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.4/esm/mod_web.js";
|
|
104
90
|
</script>
|
|
105
91
|
```
|
|
106
92
|
|
|
@@ -222,110 +208,137 @@ The library provides a browser-optimized version that eliminates Node.js depende
|
|
|
222
208
|
import { BookmarksParser, BookmarksTree } from "netscape-bookmark-parser/web";
|
|
223
209
|
```
|
|
224
210
|
|
|
211
|
+
> **Note:** The web-optimized version uses native browser APIs (DOMParser, etc.) and does not include Node.js polyfills, making it lighter and faster in browser environments.
|
|
212
|
+
|
|
225
213
|
### BookmarksParser Class
|
|
226
214
|
|
|
227
|
-
|
|
215
|
+
`BookmarksParser` provides static methods to parse Netscape Bookmark format HTML or JSON and convert them into `BookmarksTree` instances.
|
|
228
216
|
|
|
229
|
-
####
|
|
217
|
+
#### Static Methods
|
|
230
218
|
|
|
231
|
-
|
|
219
|
+
- [`static parse(htmlString: string): BookmarksTree`](#static-parsehtmlstring-string-bookmarkstree)
|
|
232
220
|
|
|
233
|
-
-
|
|
234
|
-
-
|
|
221
|
+
- Parses a Netscape Bookmark format HTML string and returns a `BookmarksTree`.
|
|
222
|
+
- Alias for [`parseFromHTMLString`](#static-parsefromhtmlstringhtmlstring-string-bookmarkstree).
|
|
235
223
|
|
|
236
|
-
**Example:**
|
|
224
|
+
**Example:**
|
|
237
225
|
|
|
238
|
-
```typescript
|
|
239
|
-
const
|
|
240
|
-
const tree = BookmarksParser.parse(
|
|
241
|
-
|
|
226
|
+
```typescript
|
|
227
|
+
const html = `<!DOCTYPE NETSCAPE-Bookmark-file-1>\n<HTML><BODY><DL><p>\n <DT><A HREF=\"https://example.com\">Example</A>\n</DL><p></BODY></HTML>`;
|
|
228
|
+
const tree = BookmarksParser.parse(html);
|
|
229
|
+
console.log(tree.toJSON());
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
- [`static parseFromHTMLString(htmlString: string): BookmarksTree`](#static-parsefromhtmlstringhtmlstring-string-bookmarkstree)
|
|
233
|
+
|
|
234
|
+
- Parses a Netscape Bookmark format HTML string and returns a `BookmarksTree`.
|
|
235
|
+
|
|
236
|
+
**Example:**
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
const html = `<!DOCTYPE NETSCAPE-Bookmark-file-1>...`;
|
|
240
|
+
const tree = BookmarksParser.parseFromHTMLString(html);
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
- [`static parseFromDOM(dom: HTMLDocument): BookmarksTree`](#static-parsefromdomdom-htmldocument-bookmarkstree)
|
|
244
|
+
|
|
245
|
+
- Converts an existing `HTMLDocument` to a `BookmarksTree`.
|
|
246
|
+
|
|
247
|
+
**Example:**
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
const dom = new DOMParser().parseFromString(html, "text/html");
|
|
251
|
+
const tree = BookmarksParser.parseFromDOM(dom);
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
- [`static parseFromJSON(jsonString: string): BookmarksTree`](#static-parsefromjsonjsonstring-string-bookmarkstree)
|
|
255
|
+
|
|
256
|
+
- Parses a JSON string and returns a `BookmarksTree`.
|
|
257
|
+
|
|
258
|
+
**Example:**
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
const json = '{"Google": "https://google.com"}';
|
|
262
|
+
const tree = BookmarksParser.parseFromJSON(json);
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
---
|
|
242
266
|
|
|
243
267
|
### BookmarksTree Class
|
|
244
268
|
|
|
245
|
-
|
|
269
|
+
`BookmarksTree` extends `Map` and manages folders (`BookmarksTree`) and bookmarks (URL strings) in a hierarchical structure.
|
|
246
270
|
|
|
247
271
|
#### Constructor
|
|
248
272
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
273
|
+
- [`new BookmarksTree()`](#constructor)
|
|
274
|
+
|
|
275
|
+
**Example:**
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
const tree = new BookmarksTree();
|
|
279
|
+
tree.set("Google", "https://google.com");
|
|
280
|
+
```
|
|
252
281
|
|
|
253
282
|
#### Instance Methods
|
|
254
283
|
|
|
255
|
-
|
|
284
|
+
- [`toJSON(): Record<string, unknown>`](#tojson-recordstring-unknown)
|
|
256
285
|
|
|
257
|
-
|
|
286
|
+
- Converts the tree to a JSON object representation.
|
|
258
287
|
|
|
259
|
-
|
|
260
|
-
const json = tree.toJSON();
|
|
261
|
-
console.log(JSON.stringify(json, null, 2));
|
|
262
|
-
```
|
|
288
|
+
**Example:**
|
|
263
289
|
|
|
264
|
-
|
|
290
|
+
```typescript
|
|
291
|
+
const json = tree.toJSON();
|
|
292
|
+
console.log(json);
|
|
293
|
+
```
|
|
265
294
|
|
|
266
|
-
|
|
295
|
+
- [`toDOM(): HTMLDocument`](#todom-htmldocument)
|
|
267
296
|
|
|
268
|
-
|
|
269
|
-
const htmlDocument = tree.toDOM();
|
|
270
|
-
```
|
|
297
|
+
- Converts the tree to a Netscape Bookmark format HTML document.
|
|
271
298
|
|
|
272
|
-
|
|
299
|
+
**Example:**
|
|
273
300
|
|
|
274
|
-
|
|
301
|
+
```typescript
|
|
302
|
+
const dom = tree.toDOM();
|
|
303
|
+
```
|
|
275
304
|
|
|
276
|
-
|
|
277
|
-
const htmlString = tree.HTMLText;
|
|
278
|
-
console.log(htmlString); // Complete HTML bookmark file
|
|
279
|
-
```
|
|
305
|
+
- [`get HTMLString(): string`](#get-htmlstring-string)
|
|
280
306
|
|
|
281
|
-
|
|
307
|
+
- Gets the complete HTML string in Netscape Bookmark format.
|
|
282
308
|
|
|
283
|
-
|
|
309
|
+
**Example:**
|
|
284
310
|
|
|
285
|
-
|
|
311
|
+
```typescript
|
|
312
|
+
const html = tree.HTMLString;
|
|
313
|
+
console.log(html);
|
|
314
|
+
```
|
|
286
315
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
316
|
+
- [`get HTMLText(): string`](#get-htmltext-string)
|
|
317
|
+
- Alias for `HTMLString` (deprecated).
|
|
318
|
+
|
|
319
|
+
#### Static Methods
|
|
291
320
|
|
|
292
|
-
|
|
321
|
+
- [`static fromJSON(json: Record<string, unknown>): BookmarksTree`](#static-fromjsonjson-recordstring-unknown-bookmarkstree)
|
|
293
322
|
|
|
294
|
-
|
|
323
|
+
- Creates a tree from a JSON object.
|
|
295
324
|
|
|
296
|
-
|
|
297
|
-
const dom = new DOMParser().parseFromString(htmlContent, "text/html");
|
|
298
|
-
const tree = BookmarksTree.fromDOM(dom);
|
|
299
|
-
```
|
|
325
|
+
**Example:**
|
|
300
326
|
|
|
301
|
-
|
|
327
|
+
```typescript
|
|
328
|
+
const json = { Google: "https://google.com" };
|
|
329
|
+
const tree = BookmarksTree.fromJSON(json);
|
|
330
|
+
```
|
|
302
331
|
|
|
303
|
-
|
|
332
|
+
- [`static fromDOM(dom: HTMLDocument): BookmarksTree`](#static-fromdomdom-htmldocument-bookmarkstree)
|
|
304
333
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
// Check existence
|
|
315
|
-
tree.has("bookmark"); // true
|
|
316
|
-
|
|
317
|
-
// Delete items
|
|
318
|
-
tree.delete("bookmark");
|
|
319
|
-
|
|
320
|
-
// Iterate
|
|
321
|
-
for (const [name, value] of tree) {
|
|
322
|
-
if (typeof value === "string") {
|
|
323
|
-
console.log(`Bookmark: ${name} -> ${value}`);
|
|
324
|
-
} else {
|
|
325
|
-
console.log(`Folder: ${name} (${value.size} items)`);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
```
|
|
334
|
+
- Creates a tree from an HTML document.
|
|
335
|
+
|
|
336
|
+
**Example:**
|
|
337
|
+
|
|
338
|
+
```typescript
|
|
339
|
+
const dom = new DOMParser().parseFromString(html, "text/html");
|
|
340
|
+
const tree = BookmarksTree.fromDOM(dom);
|
|
341
|
+
```
|
|
329
342
|
|
|
330
343
|
## Project Structure
|
|
331
344
|
|
|
@@ -375,117 +388,10 @@ npm/ # Node.js build artifacts
|
|
|
375
388
|
- **Empty Folder Support**: Preserves empty folders in the bookmark structure
|
|
376
389
|
- **Duplicate Handling**: Last value wins for duplicate bookmark names
|
|
377
390
|
|
|
378
|
-
## Output Examples
|
|
379
|
-
|
|
380
|
-
### JSON Format
|
|
381
|
-
|
|
382
|
-
```json
|
|
383
|
-
{
|
|
384
|
-
"Development": {
|
|
385
|
-
"MDN": "https://developer.mozilla.org",
|
|
386
|
-
"Tools": {
|
|
387
|
-
"GitHub": "https://github.com",
|
|
388
|
-
"Stack Overflow": "https://stackoverflow.com"
|
|
389
|
-
}
|
|
390
|
-
},
|
|
391
|
-
"Google": "https://google.com"
|
|
392
|
-
}
|
|
393
|
-
```
|
|
394
|
-
|
|
395
|
-
### HTML Format
|
|
396
|
-
|
|
397
|
-
```html
|
|
398
|
-
<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
399
|
-
<HTML>
|
|
400
|
-
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
|
|
401
|
-
<TITLE>Bookmark</TITLE>
|
|
402
|
-
<H1>Bookmark</H1>
|
|
403
|
-
<BODY>
|
|
404
|
-
<DL><p>
|
|
405
|
-
<DT><H3>Development</H3>
|
|
406
|
-
<DL><p>
|
|
407
|
-
<DT><A HREF="https://developer.mozilla.org">MDN</A>
|
|
408
|
-
<DT><H3>Tools</H3>
|
|
409
|
-
<DL><p>
|
|
410
|
-
<DT><A HREF="https://github.com">GitHub</A>
|
|
411
|
-
<DT><A HREF="https://stackoverflow.com">Stack Overflow</A>
|
|
412
|
-
</DL><p>
|
|
413
|
-
</DL><p>
|
|
414
|
-
<DT><A HREF="https://google.com">Google</A>
|
|
415
|
-
</DL>
|
|
416
|
-
</BODY>
|
|
417
|
-
</HTML>
|
|
418
|
-
```
|
|
419
|
-
|
|
420
391
|
## Dependencies
|
|
421
392
|
|
|
422
393
|
- [`@b-fuze/deno-dom`](https://jsr.io/@b-fuze/deno-dom): DOM parser and manipulation for both Deno and Node.js environments
|
|
423
394
|
|
|
424
|
-
## Development
|
|
425
|
-
|
|
426
|
-
### Prerequisites
|
|
427
|
-
|
|
428
|
-
- [Deno](https://deno.land/) 1.x or later
|
|
429
|
-
|
|
430
|
-
### Setup
|
|
431
|
-
|
|
432
|
-
```bash
|
|
433
|
-
git clone https://github.com/grakeice/netscape-bookmark-parser.git
|
|
434
|
-
cd netscape-bookmark-parser
|
|
435
|
-
```
|
|
436
|
-
|
|
437
|
-
### Development Commands
|
|
438
|
-
|
|
439
|
-
```bash
|
|
440
|
-
# Run development server with file watching
|
|
441
|
-
deno task dev
|
|
442
|
-
|
|
443
|
-
# Run all tests
|
|
444
|
-
deno test
|
|
445
|
-
|
|
446
|
-
# Run tests with coverage
|
|
447
|
-
deno test --coverage
|
|
448
|
-
|
|
449
|
-
# Format code
|
|
450
|
-
deno fmt
|
|
451
|
-
|
|
452
|
-
# Lint code
|
|
453
|
-
deno lint
|
|
454
|
-
|
|
455
|
-
# Build for Node.js
|
|
456
|
-
deno task build:npm
|
|
457
|
-
|
|
458
|
-
# Build with specific version
|
|
459
|
-
deno task build:npm 1.0.0
|
|
460
|
-
```
|
|
461
|
-
|
|
462
|
-
### Running Tests
|
|
463
|
-
|
|
464
|
-
The project includes comprehensive test suites for all functionality:
|
|
465
|
-
|
|
466
|
-
```bash
|
|
467
|
-
# Run all tests
|
|
468
|
-
deno test
|
|
469
|
-
|
|
470
|
-
# Run specific test file
|
|
471
|
-
deno test src/BookmarksTree/BookmarksTree.test.ts
|
|
472
|
-
|
|
473
|
-
# Run tests with detailed output
|
|
474
|
-
deno test --verbose
|
|
475
|
-
|
|
476
|
-
# Run tests and generate coverage report
|
|
477
|
-
deno test --coverage=coverage_dir
|
|
478
|
-
deno coverage coverage_dir
|
|
479
|
-
```
|
|
480
|
-
|
|
481
|
-
### Publishing
|
|
482
|
-
|
|
483
|
-
The project uses automated publishing via GitHub Actions:
|
|
484
|
-
|
|
485
|
-
1. Create a version tag: `git tag v1.0.0`
|
|
486
|
-
2. Push the tag: `git push origin v1.0.0`
|
|
487
|
-
3. GitHub Actions will automatically build and publish to both NPM and JSR
|
|
488
|
-
|
|
489
395
|
## Browser Compatibility
|
|
490
396
|
|
|
491
397
|
### Supported Browsers for Export Files
|
|
@@ -528,93 +434,10 @@ The library can parse bookmark files exported from:
|
|
|
528
434
|
</DL>
|
|
529
435
|
```
|
|
530
436
|
|
|
531
|
-
## Error Handling
|
|
532
|
-
|
|
533
|
-
The library gracefully handles various error conditions:
|
|
534
|
-
|
|
535
|
-
```typescript
|
|
536
|
-
// Invalid HTML
|
|
537
|
-
const invalidHtml = "<html><body>Not a bookmark file</body></html>";
|
|
538
|
-
const tree = BookmarksParser.parse(invalidHtml);
|
|
539
|
-
console.log(tree.size); // 0 - empty tree
|
|
540
|
-
|
|
541
|
-
// Empty content
|
|
542
|
-
const emptyTree = BookmarksParser.parse("");
|
|
543
|
-
console.log(emptyTree.size); // 0
|
|
544
|
-
|
|
545
|
-
// Malformed URLs are skipped
|
|
546
|
-
const htmlWithBadUrls = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
547
|
-
<HTML><BODY><DL><p>
|
|
548
|
-
<DT><A HREF="">Empty URL</A>
|
|
549
|
-
<DT><A>No HREF attribute</A>
|
|
550
|
-
<DT><A HREF="https://valid.com">Valid Link</A>
|
|
551
|
-
</DL><p></BODY></HTML>`;
|
|
552
|
-
|
|
553
|
-
const parsedTree = BookmarksParser.parse(htmlWithBadUrls);
|
|
554
|
-
console.log(parsedTree.size); // 1 - only valid link included
|
|
555
|
-
```
|
|
556
|
-
|
|
557
|
-
## Performance
|
|
558
|
-
|
|
559
|
-
The library is optimized for performance:
|
|
560
|
-
|
|
561
|
-
- **Memory Efficient**: Uses native Map structure for O(1) lookups
|
|
562
|
-
- **Streaming Capable**: Can handle large bookmark files (1000+ bookmarks)
|
|
563
|
-
- **Fast Parsing**: DOM-based parsing with efficient tree traversal
|
|
564
|
-
- **JSON Conversion**: Optimized serialization/deserialization
|
|
565
|
-
|
|
566
|
-
## TypeScript Support
|
|
567
|
-
|
|
568
|
-
Full TypeScript definitions included:
|
|
569
|
-
|
|
570
|
-
```typescript
|
|
571
|
-
interface BookmarkValue extends Map<string, string | BookmarksTree> {
|
|
572
|
-
toJSON(): Record<string, unknown>;
|
|
573
|
-
toDOM(): HTMLDocument;
|
|
574
|
-
readonly HTMLText: string;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
class BookmarksParser {
|
|
578
|
-
static parse(htmlContent: string): BookmarksTree;
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
class BookmarksTree extends Map<string, string | BookmarksTree> {
|
|
582
|
-
toJSON(): Record<string, unknown>;
|
|
583
|
-
static fromJSON(json: Record<string, unknown>): BookmarksTree;
|
|
584
|
-
static fromDOM(dom: HTMLDocument): BookmarksTree;
|
|
585
|
-
toDOM(): HTMLDocument;
|
|
586
|
-
get HTMLText(): string;
|
|
587
|
-
}
|
|
588
|
-
```
|
|
589
|
-
|
|
590
437
|
## License
|
|
591
438
|
|
|
592
439
|
MIT License - See [LICENSE](LICENSE) file for details.
|
|
593
440
|
|
|
594
|
-
## Contributing
|
|
595
|
-
|
|
596
|
-
Pull requests and issue reports are welcome!
|
|
597
|
-
|
|
598
|
-
### How to Contribute
|
|
599
|
-
|
|
600
|
-
1. Fork this repository
|
|
601
|
-
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
602
|
-
3. Make your changes with tests
|
|
603
|
-
4. Ensure all tests pass (`deno test`)
|
|
604
|
-
5. Format your code (`deno fmt`)
|
|
605
|
-
6. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
606
|
-
7. Push to the branch (`git push origin feature/amazing-feature`)
|
|
607
|
-
8. Create a pull request
|
|
608
|
-
|
|
609
|
-
### Reporting Issues
|
|
610
|
-
|
|
611
|
-
When reporting issues, please include:
|
|
612
|
-
|
|
613
|
-
- Browser/environment information
|
|
614
|
-
- Sample bookmark HTML (if applicable)
|
|
615
|
-
- Expected vs actual behavior
|
|
616
|
-
- Steps to reproduce
|
|
617
|
-
|
|
618
441
|
## Author
|
|
619
442
|
|
|
620
443
|
**grakeice**
|
|
@@ -623,7 +446,19 @@ When reporting issues, please include:
|
|
|
623
446
|
|
|
624
447
|
## Changelog
|
|
625
448
|
|
|
626
|
-
### v1.1.
|
|
449
|
+
### v1.1.4 (Latest)
|
|
450
|
+
|
|
451
|
+
- 🛠️ **Improved parser** (better compatibility with various bookmark HTML formats, increased stability)
|
|
452
|
+
- 🧹 **Code refactoring and additional tests**
|
|
453
|
+
- 🐞 **Minor bug fixes**
|
|
454
|
+
- 📚 **Documentation Update**: API Reference refresh, unified explanations, added usage examples, revived various sections
|
|
455
|
+
|
|
456
|
+
### v1.1.3
|
|
457
|
+
|
|
458
|
+
- 📝 **Added JSDoc comments**: Added JSDoc-style comments to major classes and methods to improve type information and enable automatic API documentation generation
|
|
459
|
+
- 📚 **Documentation Update**: Added TypeScript import example for Node.js/npm in the Installation section
|
|
460
|
+
|
|
461
|
+
### v1.1.2
|
|
627
462
|
|
|
628
463
|
- 📝 **Documentation Enhancement**: Updated comprehensive README documentation with latest version references and improved examples
|
|
629
464
|
- 🔧 **Version Consistency**: Synchronized version numbers across all documentation and code examples
|
|
@@ -4,8 +4,127 @@
|
|
|
4
4
|
* This software is released under the MIT License.
|
|
5
5
|
* https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
+
import type { HTMLDocument } from "../deps.js";
|
|
7
8
|
import { BookmarksTree } from "../BookmarksTree/index.js";
|
|
9
|
+
/**
|
|
10
|
+
* A parser for Netscape Bookmark format files
|
|
11
|
+
*
|
|
12
|
+
* This class provides static methods to parse Netscape Bookmark format HTML strings
|
|
13
|
+
* and convert them into BookmarksTree instances for easier manipulation.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
18
|
+
* <HTML>
|
|
19
|
+
* <BODY>
|
|
20
|
+
* <DL><p>
|
|
21
|
+
* <DT><A HREF="https://google.com">Google</A>
|
|
22
|
+
* <DT><H3>Development</H3>
|
|
23
|
+
* <DL><p>
|
|
24
|
+
* <DT><A HREF="https://github.com">GitHub</A>
|
|
25
|
+
* </DL><p>
|
|
26
|
+
* </DL>
|
|
27
|
+
* </BODY>
|
|
28
|
+
* </HTML>`;
|
|
29
|
+
*
|
|
30
|
+
* const tree = BookmarksParser.parse(bookmarkHtml);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
8
33
|
export declare class BookmarksParser {
|
|
9
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Alias for the {@link parseFromHTMLString} method.
|
|
36
|
+
*
|
|
37
|
+
* @param htmlString HTML string in Netscape Bookmark format
|
|
38
|
+
* @returns The parsed BookmarksTree
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
43
|
+
* <HTML>
|
|
44
|
+
* <BODY>
|
|
45
|
+
* <DL><p>
|
|
46
|
+
* <DT><A HREF="https://google.com">Google</A>
|
|
47
|
+
* <DT><H3>Development</H3>
|
|
48
|
+
* <DL><p>
|
|
49
|
+
* <DT><A HREF="https://github.com">GitHub</A>
|
|
50
|
+
* </DL><p>
|
|
51
|
+
* </DL>
|
|
52
|
+
* </BODY>
|
|
53
|
+
* </HTML>`;
|
|
54
|
+
*
|
|
55
|
+
* const tree = BookmarksParser.parse(bookmarkHtml);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
static parse(htmlString: string): BookmarksTree;
|
|
59
|
+
/**
|
|
60
|
+
* Parses a Netscape Bookmark format HTML string and returns a BookmarksTree.
|
|
61
|
+
*
|
|
62
|
+
* @param htmlString HTML string in Netscape Bookmark format
|
|
63
|
+
* @returns The parsed BookmarksTree
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
68
|
+
* <HTML>
|
|
69
|
+
* <BODY>
|
|
70
|
+
* <DL><p>
|
|
71
|
+
* <DT><A HREF="https://google.com">Google</A>
|
|
72
|
+
* <DT><H3>Development</H3>
|
|
73
|
+
* <DL><p>
|
|
74
|
+
* <DT><A HREF="https://github.com">GitHub</A>
|
|
75
|
+
* </DL><p>
|
|
76
|
+
* </DL>
|
|
77
|
+
* </BODY>
|
|
78
|
+
* </HTML>`;
|
|
79
|
+
*
|
|
80
|
+
* const tree = BookmarksParser.parseFromHTMLString(bookmarkHtml);
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
static parseFromHTMLString(htmlString: string): BookmarksTree;
|
|
84
|
+
/**
|
|
85
|
+
* Creates a BookmarksTree from an existing HTMLDocument.
|
|
86
|
+
*
|
|
87
|
+
* This is an alias for {@link BookmarksTree.fromDOM}.
|
|
88
|
+
*
|
|
89
|
+
* Use this when you already have a parsed HTMLDocument and want to convert it to a BookmarksTree.
|
|
90
|
+
*
|
|
91
|
+
* @param dom An HTMLDocument instance
|
|
92
|
+
* @returns The parsed BookmarksTree
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const dom = new DOMParser().parseFromString(bookmarkHtml, "text/html");
|
|
97
|
+
* const tree = BookmarksParser.parseFromDOM(dom);
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
static parseFromDOM(dom: HTMLDocument): BookmarksTree;
|
|
101
|
+
/**
|
|
102
|
+
* Parses a JSON string and returns a BookmarksTree.
|
|
103
|
+
*
|
|
104
|
+
* @param jsonString JSON string representing the bookmark structure
|
|
105
|
+
* @returns The parsed BookmarksTree
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const json = '{"Google":"https://google.com","Development":{"GitHub":"https://github.com"}}';
|
|
110
|
+
* const tree = BookmarksParser.parseFromJSONString(json);
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
static parseFromJSONString(jsonString: string): BookmarksTree;
|
|
114
|
+
/**
|
|
115
|
+
* Parses a JSON object and returns a BookmarksTree.
|
|
116
|
+
*
|
|
117
|
+
* This is an alias for {@link BookmarksTree.fromJSON}.
|
|
118
|
+
*
|
|
119
|
+
* @param jsonObj JSON object representing the bookmark structure
|
|
120
|
+
* @returns The parsed BookmarksTree
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const obj = { "Google": "https://google.com", "Development": { "GitHub": "https://github.com" } };
|
|
125
|
+
* const tree = BookmarksParser.parseFromJSON(obj);
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
static parseFromJSON(jsonObj: Record<string, unknown>): BookmarksTree;
|
|
10
129
|
}
|
|
11
130
|
//# sourceMappingURL=BookmarksParser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BookmarksParser.d.ts","sourceRoot":"","sources":["../../../src/src/BookmarksParser/BookmarksParser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,qBAAa,eAAe;IAC3B,MAAM,CAAC,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"BookmarksParser.d.ts","sourceRoot":"","sources":["../../../src/src/BookmarksParser/BookmarksParser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,eAAe;IAC3B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa;IAI/C;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa;IAM7D;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,YAAY,GAAG,aAAa;IAIrD;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa;IAK7D;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa;CAGrE"}
|