netscape-bookmark-parser 1.1.3 → 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 +194 -357
- package/README.md +108 -268
- package/esm/src/BookmarksParser/BookmarksParser.d.ts +74 -10
- package/esm/src/BookmarksParser/BookmarksParser.d.ts.map +1 -1
- package/esm/src/BookmarksParser/BookmarksParser.js +83 -11
- package/esm/src/BookmarksTree/BookmarksTree.d.ts +7 -1
- package/esm/src/BookmarksTree/BookmarksTree.d.ts.map +1 -1
- package/esm/src/BookmarksTree/BookmarksTree.js +11 -3
- package/esm/src/web/BookmarksParser/BookmarksParser.d.ts +74 -10
- package/esm/src/web/BookmarksParser/BookmarksParser.d.ts.map +1 -1
- package/esm/src/web/BookmarksParser/BookmarksParser.js +83 -11
- package/esm/src/web/BookmarksTree/BookmarksTree.d.ts +7 -1
- package/esm/src/web/BookmarksTree/BookmarksTree.d.ts.map +1 -1
- package/esm/src/web/BookmarksTree/BookmarksTree.js +11 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
} from "jsr:@grakeice/netscape-bookmark-parser";
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
> **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.
|
|
40
40
|
|
|
41
41
|
### Browser
|
|
42
42
|
|
|
@@ -69,14 +69,12 @@ function handleFileUpload(event: Event) {
|
|
|
69
69
|
<script type="importmap">
|
|
70
70
|
{
|
|
71
71
|
"imports": {
|
|
72
|
-
"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"
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
</script>
|
|
76
76
|
<script type="module">
|
|
77
77
|
import { BookmarksParser, BookmarksTree } from "netscape-bookmark-parser/web";
|
|
78
|
-
|
|
79
|
-
// Works the same as local imports
|
|
80
78
|
const tree = BookmarksParser.parse(htmlContent);
|
|
81
79
|
</script>
|
|
82
80
|
```
|
|
@@ -88,9 +86,7 @@ function handleFileUpload(event: Event) {
|
|
|
88
86
|
import {
|
|
89
87
|
BookmarksParser,
|
|
90
88
|
BookmarksTree,
|
|
91
|
-
} from "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.
|
|
92
|
-
|
|
93
|
-
// Direct CDN import without import maps
|
|
89
|
+
} from "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.4/esm/mod_web.js";
|
|
94
90
|
</script>
|
|
95
91
|
```
|
|
96
92
|
|
|
@@ -212,110 +208,137 @@ The library provides a browser-optimized version that eliminates Node.js depende
|
|
|
212
208
|
import { BookmarksParser, BookmarksTree } from "netscape-bookmark-parser/web";
|
|
213
209
|
```
|
|
214
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
|
+
|
|
215
213
|
### BookmarksParser Class
|
|
216
214
|
|
|
217
|
-
|
|
215
|
+
`BookmarksParser` provides static methods to parse Netscape Bookmark format HTML or JSON and convert them into `BookmarksTree` instances.
|
|
218
216
|
|
|
219
|
-
####
|
|
217
|
+
#### Static Methods
|
|
220
218
|
|
|
221
|
-
|
|
219
|
+
- [`static parse(htmlString: string): BookmarksTree`](#static-parsehtmlstring-string-bookmarkstree)
|
|
222
220
|
|
|
223
|
-
-
|
|
224
|
-
-
|
|
221
|
+
- Parses a Netscape Bookmark format HTML string and returns a `BookmarksTree`.
|
|
222
|
+
- Alias for [`parseFromHTMLString`](#static-parsefromhtmlstringhtmlstring-string-bookmarkstree).
|
|
225
223
|
|
|
226
|
-
**Example:**
|
|
224
|
+
**Example:**
|
|
227
225
|
|
|
228
|
-
```typescript
|
|
229
|
-
const
|
|
230
|
-
const tree = BookmarksParser.parse(
|
|
231
|
-
|
|
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
|
+
---
|
|
232
266
|
|
|
233
267
|
### BookmarksTree Class
|
|
234
268
|
|
|
235
|
-
|
|
269
|
+
`BookmarksTree` extends `Map` and manages folders (`BookmarksTree`) and bookmarks (URL strings) in a hierarchical structure.
|
|
236
270
|
|
|
237
271
|
#### Constructor
|
|
238
272
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
273
|
+
- [`new BookmarksTree()`](#constructor)
|
|
274
|
+
|
|
275
|
+
**Example:**
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
const tree = new BookmarksTree();
|
|
279
|
+
tree.set("Google", "https://google.com");
|
|
280
|
+
```
|
|
242
281
|
|
|
243
282
|
#### Instance Methods
|
|
244
283
|
|
|
245
|
-
|
|
284
|
+
- [`toJSON(): Record<string, unknown>`](#tojson-recordstring-unknown)
|
|
246
285
|
|
|
247
|
-
|
|
286
|
+
- Converts the tree to a JSON object representation.
|
|
248
287
|
|
|
249
|
-
|
|
250
|
-
const json = tree.toJSON();
|
|
251
|
-
console.log(JSON.stringify(json, null, 2));
|
|
252
|
-
```
|
|
288
|
+
**Example:**
|
|
253
289
|
|
|
254
|
-
|
|
290
|
+
```typescript
|
|
291
|
+
const json = tree.toJSON();
|
|
292
|
+
console.log(json);
|
|
293
|
+
```
|
|
255
294
|
|
|
256
|
-
|
|
295
|
+
- [`toDOM(): HTMLDocument`](#todom-htmldocument)
|
|
257
296
|
|
|
258
|
-
|
|
259
|
-
const htmlDocument = tree.toDOM();
|
|
260
|
-
```
|
|
297
|
+
- Converts the tree to a Netscape Bookmark format HTML document.
|
|
261
298
|
|
|
262
|
-
|
|
299
|
+
**Example:**
|
|
263
300
|
|
|
264
|
-
|
|
301
|
+
```typescript
|
|
302
|
+
const dom = tree.toDOM();
|
|
303
|
+
```
|
|
265
304
|
|
|
266
|
-
|
|
267
|
-
const htmlString = tree.HTMLText;
|
|
268
|
-
console.log(htmlString); // Complete HTML bookmark file
|
|
269
|
-
```
|
|
305
|
+
- [`get HTMLString(): string`](#get-htmlstring-string)
|
|
270
306
|
|
|
271
|
-
|
|
307
|
+
- Gets the complete HTML string in Netscape Bookmark format.
|
|
272
308
|
|
|
273
|
-
|
|
309
|
+
**Example:**
|
|
274
310
|
|
|
275
|
-
|
|
311
|
+
```typescript
|
|
312
|
+
const html = tree.HTMLString;
|
|
313
|
+
console.log(html);
|
|
314
|
+
```
|
|
276
315
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const tree = BookmarksTree.fromJSON(json);
|
|
280
|
-
```
|
|
316
|
+
- [`get HTMLText(): string`](#get-htmltext-string)
|
|
317
|
+
- Alias for `HTMLString` (deprecated).
|
|
281
318
|
|
|
282
|
-
|
|
319
|
+
#### Static Methods
|
|
283
320
|
|
|
284
|
-
|
|
321
|
+
- [`static fromJSON(json: Record<string, unknown>): BookmarksTree`](#static-fromjsonjson-recordstring-unknown-bookmarkstree)
|
|
285
322
|
|
|
286
|
-
|
|
287
|
-
const dom = new DOMParser().parseFromString(htmlContent, "text/html");
|
|
288
|
-
const tree = BookmarksTree.fromDOM(dom);
|
|
289
|
-
```
|
|
323
|
+
- Creates a tree from a JSON object.
|
|
290
324
|
|
|
291
|
-
|
|
325
|
+
**Example:**
|
|
292
326
|
|
|
293
|
-
|
|
327
|
+
```typescript
|
|
328
|
+
const json = { Google: "https://google.com" };
|
|
329
|
+
const tree = BookmarksTree.fromJSON(json);
|
|
330
|
+
```
|
|
294
331
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
tree
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
tree.has("bookmark"); // true
|
|
306
|
-
|
|
307
|
-
// Delete items
|
|
308
|
-
tree.delete("bookmark");
|
|
309
|
-
|
|
310
|
-
// Iterate
|
|
311
|
-
for (const [name, value] of tree) {
|
|
312
|
-
if (typeof value === "string") {
|
|
313
|
-
console.log(`Bookmark: ${name} -> ${value}`);
|
|
314
|
-
} else {
|
|
315
|
-
console.log(`Folder: ${name} (${value.size} items)`);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
```
|
|
332
|
+
- [`static fromDOM(dom: HTMLDocument): BookmarksTree`](#static-fromdomdom-htmldocument-bookmarkstree)
|
|
333
|
+
|
|
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
|
+
```
|
|
319
342
|
|
|
320
343
|
## Project Structure
|
|
321
344
|
|
|
@@ -365,117 +388,10 @@ npm/ # Node.js build artifacts
|
|
|
365
388
|
- **Empty Folder Support**: Preserves empty folders in the bookmark structure
|
|
366
389
|
- **Duplicate Handling**: Last value wins for duplicate bookmark names
|
|
367
390
|
|
|
368
|
-
## Output Examples
|
|
369
|
-
|
|
370
|
-
### JSON Format
|
|
371
|
-
|
|
372
|
-
```json
|
|
373
|
-
{
|
|
374
|
-
"Development": {
|
|
375
|
-
"MDN": "https://developer.mozilla.org",
|
|
376
|
-
"Tools": {
|
|
377
|
-
"GitHub": "https://github.com",
|
|
378
|
-
"Stack Overflow": "https://stackoverflow.com"
|
|
379
|
-
}
|
|
380
|
-
},
|
|
381
|
-
"Google": "https://google.com"
|
|
382
|
-
}
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
### HTML Format
|
|
386
|
-
|
|
387
|
-
```html
|
|
388
|
-
<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
389
|
-
<HTML>
|
|
390
|
-
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
|
|
391
|
-
<TITLE>Bookmark</TITLE>
|
|
392
|
-
<H1>Bookmark</H1>
|
|
393
|
-
<BODY>
|
|
394
|
-
<DL><p>
|
|
395
|
-
<DT><H3>Development</H3>
|
|
396
|
-
<DL><p>
|
|
397
|
-
<DT><A HREF="https://developer.mozilla.org">MDN</A>
|
|
398
|
-
<DT><H3>Tools</H3>
|
|
399
|
-
<DL><p>
|
|
400
|
-
<DT><A HREF="https://github.com">GitHub</A>
|
|
401
|
-
<DT><A HREF="https://stackoverflow.com">Stack Overflow</A>
|
|
402
|
-
</DL><p>
|
|
403
|
-
</DL><p>
|
|
404
|
-
<DT><A HREF="https://google.com">Google</A>
|
|
405
|
-
</DL>
|
|
406
|
-
</BODY>
|
|
407
|
-
</HTML>
|
|
408
|
-
```
|
|
409
|
-
|
|
410
391
|
## Dependencies
|
|
411
392
|
|
|
412
393
|
- [`@b-fuze/deno-dom`](https://jsr.io/@b-fuze/deno-dom): DOM parser and manipulation for both Deno and Node.js environments
|
|
413
394
|
|
|
414
|
-
## Development
|
|
415
|
-
|
|
416
|
-
### Prerequisites
|
|
417
|
-
|
|
418
|
-
- [Deno](https://deno.land/) 1.x or later
|
|
419
|
-
|
|
420
|
-
### Setup
|
|
421
|
-
|
|
422
|
-
```bash
|
|
423
|
-
git clone https://github.com/grakeice/netscape-bookmark-parser.git
|
|
424
|
-
cd netscape-bookmark-parser
|
|
425
|
-
```
|
|
426
|
-
|
|
427
|
-
### Development Commands
|
|
428
|
-
|
|
429
|
-
```bash
|
|
430
|
-
# Run development server with file watching
|
|
431
|
-
deno task dev
|
|
432
|
-
|
|
433
|
-
# Run all tests
|
|
434
|
-
deno test
|
|
435
|
-
|
|
436
|
-
# Run tests with coverage
|
|
437
|
-
deno test --coverage
|
|
438
|
-
|
|
439
|
-
# Format code
|
|
440
|
-
deno fmt
|
|
441
|
-
|
|
442
|
-
# Lint code
|
|
443
|
-
deno lint
|
|
444
|
-
|
|
445
|
-
# Build for Node.js
|
|
446
|
-
deno task build:npm
|
|
447
|
-
|
|
448
|
-
# Build with specific version
|
|
449
|
-
deno task build:npm 1.0.0
|
|
450
|
-
```
|
|
451
|
-
|
|
452
|
-
### Running Tests
|
|
453
|
-
|
|
454
|
-
The project includes comprehensive test suites for all functionality:
|
|
455
|
-
|
|
456
|
-
```bash
|
|
457
|
-
# Run all tests
|
|
458
|
-
deno test
|
|
459
|
-
|
|
460
|
-
# Run specific test file
|
|
461
|
-
deno test src/BookmarksTree/BookmarksTree.test.ts
|
|
462
|
-
|
|
463
|
-
# Run tests with detailed output
|
|
464
|
-
deno test --verbose
|
|
465
|
-
|
|
466
|
-
# Run tests and generate coverage report
|
|
467
|
-
deno test --coverage=coverage_dir
|
|
468
|
-
deno coverage coverage_dir
|
|
469
|
-
```
|
|
470
|
-
|
|
471
|
-
### Publishing
|
|
472
|
-
|
|
473
|
-
The project uses automated publishing via GitHub Actions:
|
|
474
|
-
|
|
475
|
-
1. Create a version tag: `git tag v1.0.0`
|
|
476
|
-
2. Push the tag: `git push origin v1.0.0`
|
|
477
|
-
3. GitHub Actions will automatically build and publish to both NPM and JSR
|
|
478
|
-
|
|
479
395
|
## Browser Compatibility
|
|
480
396
|
|
|
481
397
|
### Supported Browsers for Export Files
|
|
@@ -518,93 +434,10 @@ The library can parse bookmark files exported from:
|
|
|
518
434
|
</DL>
|
|
519
435
|
```
|
|
520
436
|
|
|
521
|
-
## Error Handling
|
|
522
|
-
|
|
523
|
-
The library gracefully handles various error conditions:
|
|
524
|
-
|
|
525
|
-
```typescript
|
|
526
|
-
// Invalid HTML
|
|
527
|
-
const invalidHtml = "<html><body>Not a bookmark file</body></html>";
|
|
528
|
-
const tree = BookmarksParser.parse(invalidHtml);
|
|
529
|
-
console.log(tree.size); // 0 - empty tree
|
|
530
|
-
|
|
531
|
-
// Empty content
|
|
532
|
-
const emptyTree = BookmarksParser.parse("");
|
|
533
|
-
console.log(emptyTree.size); // 0
|
|
534
|
-
|
|
535
|
-
// Malformed URLs are skipped
|
|
536
|
-
const htmlWithBadUrls = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
537
|
-
<HTML><BODY><DL><p>
|
|
538
|
-
<DT><A HREF="">Empty URL</A>
|
|
539
|
-
<DT><A>No HREF attribute</A>
|
|
540
|
-
<DT><A HREF="https://valid.com">Valid Link</A>
|
|
541
|
-
</DL><p></BODY></HTML>`;
|
|
542
|
-
|
|
543
|
-
const parsedTree = BookmarksParser.parse(htmlWithBadUrls);
|
|
544
|
-
console.log(parsedTree.size); // 1 - only valid link included
|
|
545
|
-
```
|
|
546
|
-
|
|
547
|
-
## Performance
|
|
548
|
-
|
|
549
|
-
The library is optimized for performance:
|
|
550
|
-
|
|
551
|
-
- **Memory Efficient**: Uses native Map structure for O(1) lookups
|
|
552
|
-
- **Streaming Capable**: Can handle large bookmark files (1000+ bookmarks)
|
|
553
|
-
- **Fast Parsing**: DOM-based parsing with efficient tree traversal
|
|
554
|
-
- **JSON Conversion**: Optimized serialization/deserialization
|
|
555
|
-
|
|
556
|
-
## TypeScript Support
|
|
557
|
-
|
|
558
|
-
Full TypeScript definitions included:
|
|
559
|
-
|
|
560
|
-
```typescript
|
|
561
|
-
interface BookmarkValue extends Map<string, string | BookmarksTree> {
|
|
562
|
-
toJSON(): Record<string, unknown>;
|
|
563
|
-
toDOM(): HTMLDocument;
|
|
564
|
-
readonly HTMLText: string;
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
class BookmarksParser {
|
|
568
|
-
static parse(htmlContent: string): BookmarksTree;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
class BookmarksTree extends Map<string, string | BookmarksTree> {
|
|
572
|
-
toJSON(): Record<string, unknown>;
|
|
573
|
-
static fromJSON(json: Record<string, unknown>): BookmarksTree;
|
|
574
|
-
static fromDOM(dom: HTMLDocument): BookmarksTree;
|
|
575
|
-
toDOM(): HTMLDocument;
|
|
576
|
-
get HTMLText(): string;
|
|
577
|
-
}
|
|
578
|
-
```
|
|
579
|
-
|
|
580
437
|
## License
|
|
581
438
|
|
|
582
439
|
MIT License - See [LICENSE](LICENSE) file for details.
|
|
583
440
|
|
|
584
|
-
## Contributing
|
|
585
|
-
|
|
586
|
-
Pull requests and issue reports are welcome!
|
|
587
|
-
|
|
588
|
-
### How to Contribute
|
|
589
|
-
|
|
590
|
-
1. Fork this repository
|
|
591
|
-
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
592
|
-
3. Make your changes with tests
|
|
593
|
-
4. Ensure all tests pass (`deno test`)
|
|
594
|
-
5. Format your code (`deno fmt`)
|
|
595
|
-
6. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
596
|
-
7. Push to the branch (`git push origin feature/amazing-feature`)
|
|
597
|
-
8. Create a pull request
|
|
598
|
-
|
|
599
|
-
### Reporting Issues
|
|
600
|
-
|
|
601
|
-
When reporting issues, please include:
|
|
602
|
-
|
|
603
|
-
- Browser/environment information
|
|
604
|
-
- Sample bookmark HTML (if applicable)
|
|
605
|
-
- Expected vs actual behavior
|
|
606
|
-
- Steps to reproduce
|
|
607
|
-
|
|
608
441
|
## Author
|
|
609
442
|
|
|
610
443
|
**grakeice**
|
|
@@ -613,7 +446,14 @@ When reporting issues, please include:
|
|
|
613
446
|
|
|
614
447
|
## Changelog
|
|
615
448
|
|
|
616
|
-
### 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
|
|
617
457
|
|
|
618
458
|
- 📝 **Added JSDoc comments**: Added JSDoc-style comments to major classes and methods to improve type information and enable automatic API documentation generation
|
|
619
459
|
- 📚 **Documentation Update**: Added TypeScript import example for Node.js/npm in the Installation section
|
|
@@ -4,6 +4,7 @@
|
|
|
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";
|
|
8
9
|
/**
|
|
9
10
|
* A parser for Netscape Bookmark format files
|
|
@@ -31,13 +32,10 @@ import { BookmarksTree } from "../BookmarksTree/index.js";
|
|
|
31
32
|
*/
|
|
32
33
|
export declare class BookmarksParser {
|
|
33
34
|
/**
|
|
34
|
-
*
|
|
35
|
+
* Alias for the {@link parseFromHTMLString} method.
|
|
35
36
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @param data The HTML string in Netscape Bookmark format to parse
|
|
40
|
-
* @returns A BookmarksTree representing the parsed bookmark structure
|
|
37
|
+
* @param htmlString HTML string in Netscape Bookmark format
|
|
38
|
+
* @returns The parsed BookmarksTree
|
|
41
39
|
*
|
|
42
40
|
* @example
|
|
43
41
|
* ```typescript
|
|
@@ -55,12 +53,78 @@ export declare class BookmarksParser {
|
|
|
55
53
|
* </HTML>`;
|
|
56
54
|
*
|
|
57
55
|
* const tree = BookmarksParser.parse(bookmarkHtml);
|
|
58
|
-
*
|
|
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.
|
|
59
103
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
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);
|
|
62
126
|
* ```
|
|
63
127
|
*/
|
|
64
|
-
static
|
|
128
|
+
static parseFromJSON(jsonObj: Record<string, unknown>): BookmarksTree;
|
|
65
129
|
}
|
|
66
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;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,eAAe;IAC3B
|
|
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"}
|
|
@@ -32,13 +32,10 @@ import { BookmarksTree } from "../BookmarksTree/index.js";
|
|
|
32
32
|
*/
|
|
33
33
|
export class BookmarksParser {
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* Alias for the {@link parseFromHTMLString} method.
|
|
36
36
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @param data The HTML string in Netscape Bookmark format to parse
|
|
41
|
-
* @returns A BookmarksTree representing the parsed bookmark structure
|
|
37
|
+
* @param htmlString HTML string in Netscape Bookmark format
|
|
38
|
+
* @returns The parsed BookmarksTree
|
|
42
39
|
*
|
|
43
40
|
* @example
|
|
44
41
|
* ```typescript
|
|
@@ -56,15 +53,90 @@ export class BookmarksParser {
|
|
|
56
53
|
* </HTML>`;
|
|
57
54
|
*
|
|
58
55
|
* const tree = BookmarksParser.parse(bookmarkHtml);
|
|
59
|
-
*
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
static parse(htmlString) {
|
|
59
|
+
return this.parseFromHTMLString(htmlString);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Parses a Netscape Bookmark format HTML string and returns a BookmarksTree.
|
|
63
|
+
*
|
|
64
|
+
* @param htmlString HTML string in Netscape Bookmark format
|
|
65
|
+
* @returns The parsed BookmarksTree
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
70
|
+
* <HTML>
|
|
71
|
+
* <BODY>
|
|
72
|
+
* <DL><p>
|
|
73
|
+
* <DT><A HREF="https://google.com">Google</A>
|
|
74
|
+
* <DT><H3>Development</H3>
|
|
75
|
+
* <DL><p>
|
|
76
|
+
* <DT><A HREF="https://github.com">GitHub</A>
|
|
77
|
+
* </DL><p>
|
|
78
|
+
* </DL>
|
|
79
|
+
* </BODY>
|
|
80
|
+
* </HTML>`;
|
|
60
81
|
*
|
|
61
|
-
* const
|
|
62
|
-
* console.log(folder.get("GitHub")); // "https://github.com"
|
|
82
|
+
* const tree = BookmarksParser.parseFromHTMLString(bookmarkHtml);
|
|
63
83
|
* ```
|
|
64
84
|
*/
|
|
65
|
-
static
|
|
66
|
-
const dom = new DOMParser().parseFromString(
|
|
85
|
+
static parseFromHTMLString(htmlString) {
|
|
86
|
+
const dom = new DOMParser().parseFromString(htmlString, "text/html");
|
|
67
87
|
const tree = BookmarksTree.fromDOM(dom);
|
|
68
88
|
return tree;
|
|
69
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Creates a BookmarksTree from an existing HTMLDocument.
|
|
92
|
+
*
|
|
93
|
+
* This is an alias for {@link BookmarksTree.fromDOM}.
|
|
94
|
+
*
|
|
95
|
+
* Use this when you already have a parsed HTMLDocument and want to convert it to a BookmarksTree.
|
|
96
|
+
*
|
|
97
|
+
* @param dom An HTMLDocument instance
|
|
98
|
+
* @returns The parsed BookmarksTree
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const dom = new DOMParser().parseFromString(bookmarkHtml, "text/html");
|
|
103
|
+
* const tree = BookmarksParser.parseFromDOM(dom);
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
static parseFromDOM(dom) {
|
|
107
|
+
return BookmarksTree.fromDOM(dom);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Parses a JSON string and returns a BookmarksTree.
|
|
111
|
+
*
|
|
112
|
+
* @param jsonString JSON string representing the bookmark structure
|
|
113
|
+
* @returns The parsed BookmarksTree
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const json = '{"Google":"https://google.com","Development":{"GitHub":"https://github.com"}}';
|
|
118
|
+
* const tree = BookmarksParser.parseFromJSONString(json);
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
static parseFromJSONString(jsonString) {
|
|
122
|
+
const obj = JSON.parse(jsonString);
|
|
123
|
+
return BookmarksTree.fromJSON(obj);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Parses a JSON object and returns a BookmarksTree.
|
|
127
|
+
*
|
|
128
|
+
* This is an alias for {@link BookmarksTree.fromJSON}.
|
|
129
|
+
*
|
|
130
|
+
* @param jsonObj JSON object representing the bookmark structure
|
|
131
|
+
* @returns The parsed BookmarksTree
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* const obj = { "Google": "https://google.com", "Development": { "GitHub": "https://github.com" } };
|
|
136
|
+
* const tree = BookmarksParser.parseFromJSON(obj);
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
static parseFromJSON(jsonObj) {
|
|
140
|
+
return BookmarksTree.fromJSON(jsonObj);
|
|
141
|
+
}
|
|
70
142
|
}
|