netscape-bookmark-parser 1.1.3 → 1.2.0
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/LICENSE +2 -2
- package/README-ja.md +233 -386
- package/README.md +152 -302
- package/dist/index.d.ts +240 -0
- package/dist/index.js +333 -0
- package/dist/index.js.map +1 -0
- package/dist/web.d.ts +241 -0
- package/dist/web.js +330 -0
- package/dist/web.js.map +1 -0
- package/package.json +58 -15
- package/esm/_dnt.polyfills.d.ts +0 -101
- package/esm/_dnt.polyfills.d.ts.map +0 -1
- package/esm/_dnt.polyfills.js +0 -127
- package/esm/_dnt.shims.d.ts +0 -6
- package/esm/_dnt.shims.d.ts.map +0 -1
- package/esm/_dnt.shims.js +0 -61
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/build/deno-wasm/deno-wasm.d.ts +0 -14
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/build/deno-wasm/deno-wasm.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/build/deno-wasm/deno-wasm.js +0 -151
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.d.ts +0 -23
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.js +0 -26
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/api.d.ts +0 -24
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/api.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/api.js +0 -48
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/constructor-lock.d.ts +0 -5
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/constructor-lock.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/constructor-lock.js +0 -4
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/deserialize.d.ts +0 -4
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/deserialize.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/deserialize.js +0 -61
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document-fragment.d.ts +0 -19
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document-fragment.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document-fragment.js +0 -110
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document.d.ts +0 -68
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document.js +0 -322
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/dom-parser.d.ts +0 -6
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/dom-parser.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/dom-parser.js +0 -46
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/element.d.ts +0 -127
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/element.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/element.js +0 -1068
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/elements/html-template-element.d.ts +0 -29
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/elements/html-template-element.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/elements/html-template-element.js +0 -94
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/html-collection.d.ts +0 -21
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/html-collection.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/html-collection.js +0 -80
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node-list.d.ts +0 -23
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node-list.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node-list.js +0 -159
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node.d.ts +0 -127
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node.js +0 -629
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/custom-api.d.ts +0 -6
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/custom-api.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/custom-api.js +0 -5
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi-types.d.ts +0 -12
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi-types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi-types.js +0 -2
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi.d.ts +0 -90
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi.js +0 -1611
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/selectors.d.ts +0 -16
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/selectors.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/selectors.js +0 -28
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle-types.d.ts +0 -8
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle-types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle-types.js +0 -2
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle.d.ts +0 -7
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle.js +0 -2061
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/string-cache.d.ts +0 -3
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/string-cache.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/string-cache.js +0 -10
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils-types.d.ts +0 -13
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils-types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils-types.js +0 -8
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils.d.ts +0 -31
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils.js +0 -239
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/parser.d.ts +0 -5
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/parser.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/parser.js +0 -20
- package/esm/mod.d.ts +0 -10
- package/esm/mod.d.ts.map +0 -1
- package/esm/mod.js +0 -9
- package/esm/mod_web.d.ts +0 -9
- package/esm/mod_web.d.ts.map +0 -1
- package/esm/mod_web.js +0 -8
- package/esm/package.json +0 -3
- package/esm/src/BookmarksParser/BookmarksParser.d.ts +0 -66
- package/esm/src/BookmarksParser/BookmarksParser.d.ts.map +0 -1
- package/esm/src/BookmarksParser/BookmarksParser.js +0 -70
- package/esm/src/BookmarksParser/index.d.ts +0 -8
- package/esm/src/BookmarksParser/index.d.ts.map +0 -1
- package/esm/src/BookmarksParser/index.js +0 -7
- package/esm/src/BookmarksTree/BookmarksTree.d.ts +0 -112
- package/esm/src/BookmarksTree/BookmarksTree.d.ts.map +0 -1
- package/esm/src/BookmarksTree/BookmarksTree.js +0 -217
- package/esm/src/BookmarksTree/index.d.ts +0 -8
- package/esm/src/BookmarksTree/index.d.ts.map +0 -1
- package/esm/src/BookmarksTree/index.js +0 -7
- package/esm/src/deps.d.ts +0 -9
- package/esm/src/deps.d.ts.map +0 -1
- package/esm/src/deps.js +0 -7
- package/esm/src/web/BookmarksParser/BookmarksParser.d.ts +0 -66
- package/esm/src/web/BookmarksParser/BookmarksParser.d.ts.map +0 -1
- package/esm/src/web/BookmarksParser/BookmarksParser.js +0 -70
- package/esm/src/web/BookmarksParser/index.d.ts +0 -8
- package/esm/src/web/BookmarksParser/index.d.ts.map +0 -1
- package/esm/src/web/BookmarksParser/index.js +0 -7
- package/esm/src/web/BookmarksTree/BookmarksTree.d.ts +0 -112
- package/esm/src/web/BookmarksTree/BookmarksTree.d.ts.map +0 -1
- package/esm/src/web/BookmarksTree/BookmarksTree.js +0 -217
- package/esm/src/web/BookmarksTree/index.d.ts +0 -8
- package/esm/src/web/BookmarksTree/index.d.ts.map +0 -1
- package/esm/src/web/BookmarksTree/index.js +0 -7
- package/esm/src/web/deps.d.ts +0 -10
- package/esm/src/web/deps.d.ts.map +0 -1
- package/esm/src/web/deps.js +0 -9
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 grakeice
|
|
3
|
-
*
|
|
4
|
-
* This software is released under the MIT License.
|
|
5
|
-
* https://opensource.org/licenses/MIT
|
|
6
|
-
*/
|
|
7
|
-
import { type HTMLDocument } from "../deps.js";
|
|
8
|
-
/**
|
|
9
|
-
* A class representing a bookmark tree in Netscape Bookmark format
|
|
10
|
-
*
|
|
11
|
-
* This class extends Map and manages folders (BookmarksTree) and bookmarks (URL strings)
|
|
12
|
-
* in a hierarchical structure.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* const tree = new BookmarksTree();
|
|
17
|
-
* tree.set("Google", "https://google.com");
|
|
18
|
-
*
|
|
19
|
-
* const folder = new BookmarksTree();
|
|
20
|
-
* folder.set("GitHub", "https://github.com");
|
|
21
|
-
* tree.set("Development", folder);
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export declare class BookmarksTree extends Map<string, string | BookmarksTree> {
|
|
25
|
-
/**
|
|
26
|
-
* Creates a new BookmarksTree instance
|
|
27
|
-
*/
|
|
28
|
-
constructor();
|
|
29
|
-
/**
|
|
30
|
-
* Converts the BookmarksTree to a JSON object
|
|
31
|
-
*
|
|
32
|
-
* Folders are recursively converted to objects, and bookmarks are preserved as strings.
|
|
33
|
-
*
|
|
34
|
-
* @returns JSON object representation of the bookmark data
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* const tree = new BookmarksTree();
|
|
39
|
-
* tree.set("Google", "https://google.com");
|
|
40
|
-
* const json = tree.toJSON();
|
|
41
|
-
* // { "Google": "https://google.com" }
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
toJSON(): Record<string, unknown>;
|
|
45
|
-
/**
|
|
46
|
-
* Creates a BookmarksTree from a JSON object
|
|
47
|
-
*
|
|
48
|
-
* String properties are treated as bookmarks, and object properties are
|
|
49
|
-
* recursively processed as folders.
|
|
50
|
-
*
|
|
51
|
-
* @param json The source JSON object to convert
|
|
52
|
-
* @returns A new BookmarksTree instance
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* const json = { "Google": "https://google.com", "Development": { "GitHub": "https://github.com" } };
|
|
57
|
-
* const tree = BookmarksTree.fromJSON(json);
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
static fromJSON(json: Record<string, unknown>): BookmarksTree;
|
|
61
|
-
/**
|
|
62
|
-
* Creates a BookmarksTree from an HTML document (Netscape Bookmark format)
|
|
63
|
-
*
|
|
64
|
-
* Parses Netscape Bookmark format HTML and generates a BookmarksTree that preserves
|
|
65
|
-
* the hierarchical structure. H3 elements within DT elements are treated as folders,
|
|
66
|
-
* and A elements are treated as bookmarks.
|
|
67
|
-
*
|
|
68
|
-
* @param dom The HTML document to parse
|
|
69
|
-
* @returns A new BookmarksTree instance
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```typescript
|
|
73
|
-
* const parser = new DOMParser();
|
|
74
|
-
* const dom = parser.parseFromString(bookmarkHtml, "text/html");
|
|
75
|
-
* const tree = BookmarksTree.fromDOM(dom);
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
static fromDOM(dom: HTMLDocument): BookmarksTree;
|
|
79
|
-
/**
|
|
80
|
-
* Converts the BookmarksTree to an HTML document
|
|
81
|
-
*
|
|
82
|
-
* Generates an HTML document in Netscape Bookmark format.
|
|
83
|
-
*
|
|
84
|
-
* @returns HTML document in Netscape Bookmark format
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```typescript
|
|
88
|
-
* const tree = new BookmarksTree();
|
|
89
|
-
* tree.set("Google", "https://google.com");
|
|
90
|
-
* const dom = tree.toDOM();
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
toDOM(): HTMLDocument;
|
|
94
|
-
/**
|
|
95
|
-
* Gets the BookmarksTree as an HTML string in Netscape Bookmark format
|
|
96
|
-
*
|
|
97
|
-
* Generates a complete HTML document string including DOCTYPE, metadata, and body
|
|
98
|
-
* in Netscape Bookmark format.
|
|
99
|
-
*
|
|
100
|
-
* @returns HTML string in Netscape Bookmark format
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
104
|
-
* const tree = new BookmarksTree();
|
|
105
|
-
* tree.set("Google", "https://google.com");
|
|
106
|
-
* const html = tree.HTMLText;
|
|
107
|
-
* console.log(html); // <!DOCTYPE NETSCAPE-Bookmark-file-1>...
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
|
-
get HTMLText(): string;
|
|
111
|
-
}
|
|
112
|
-
//# sourceMappingURL=BookmarksTree.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BookmarksTree.d.ts","sourceRoot":"","sources":["../../../src/src/BookmarksTree/BookmarksTree.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAA2B,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAExE;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,aAAc,SAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IACrE;;OAEG;;IAKH;;;;;;;;;;;;;;OAcG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAcjC;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa;IAmB7D;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,GAAG,aAAa;IA8ChD;;;;;;;;;;;;;OAaG;IACH,KAAK,IAAI,YAAY;IAIrB;;;;;;;;;;;;;;;OAeG;IACH,IAAI,QAAQ,IAAI,MAAM,CA+CrB;CACD"}
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 grakeice
|
|
3
|
-
*
|
|
4
|
-
* This software is released under the MIT License.
|
|
5
|
-
* https://opensource.org/licenses/MIT
|
|
6
|
-
*/
|
|
7
|
-
import { DOMParser } from "../deps.js";
|
|
8
|
-
/**
|
|
9
|
-
* A class representing a bookmark tree in Netscape Bookmark format
|
|
10
|
-
*
|
|
11
|
-
* This class extends Map and manages folders (BookmarksTree) and bookmarks (URL strings)
|
|
12
|
-
* in a hierarchical structure.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* const tree = new BookmarksTree();
|
|
17
|
-
* tree.set("Google", "https://google.com");
|
|
18
|
-
*
|
|
19
|
-
* const folder = new BookmarksTree();
|
|
20
|
-
* folder.set("GitHub", "https://github.com");
|
|
21
|
-
* tree.set("Development", folder);
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export class BookmarksTree extends Map {
|
|
25
|
-
/**
|
|
26
|
-
* Creates a new BookmarksTree instance
|
|
27
|
-
*/
|
|
28
|
-
constructor() {
|
|
29
|
-
super();
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Converts the BookmarksTree to a JSON object
|
|
33
|
-
*
|
|
34
|
-
* Folders are recursively converted to objects, and bookmarks are preserved as strings.
|
|
35
|
-
*
|
|
36
|
-
* @returns JSON object representation of the bookmark data
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```typescript
|
|
40
|
-
* const tree = new BookmarksTree();
|
|
41
|
-
* tree.set("Google", "https://google.com");
|
|
42
|
-
* const json = tree.toJSON();
|
|
43
|
-
* // { "Google": "https://google.com" }
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
toJSON() {
|
|
47
|
-
const json = {};
|
|
48
|
-
for (const [key, value] of this.entries()) {
|
|
49
|
-
if (typeof value === "string") {
|
|
50
|
-
json[key] = value;
|
|
51
|
-
}
|
|
52
|
-
else if (value instanceof BookmarksTree) {
|
|
53
|
-
json[key] = value.toJSON();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return json;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Creates a BookmarksTree from a JSON object
|
|
60
|
-
*
|
|
61
|
-
* String properties are treated as bookmarks, and object properties are
|
|
62
|
-
* recursively processed as folders.
|
|
63
|
-
*
|
|
64
|
-
* @param json The source JSON object to convert
|
|
65
|
-
* @returns A new BookmarksTree instance
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* const json = { "Google": "https://google.com", "Development": { "GitHub": "https://github.com" } };
|
|
70
|
-
* const tree = BookmarksTree.fromJSON(json);
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
static fromJSON(json) {
|
|
74
|
-
const tree = new BookmarksTree();
|
|
75
|
-
if (typeof json === "object" && json !== null) {
|
|
76
|
-
for (const [key, value] of Object.entries(json)) {
|
|
77
|
-
if (typeof value === "string") {
|
|
78
|
-
tree.set(key, value);
|
|
79
|
-
}
|
|
80
|
-
else if (typeof value === "object" && value !== null) {
|
|
81
|
-
tree.set(key, BookmarksTree.fromJSON(value));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return tree;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Creates a BookmarksTree from an HTML document (Netscape Bookmark format)
|
|
89
|
-
*
|
|
90
|
-
* Parses Netscape Bookmark format HTML and generates a BookmarksTree that preserves
|
|
91
|
-
* the hierarchical structure. H3 elements within DT elements are treated as folders,
|
|
92
|
-
* and A elements are treated as bookmarks.
|
|
93
|
-
*
|
|
94
|
-
* @param dom The HTML document to parse
|
|
95
|
-
* @returns A new BookmarksTree instance
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```typescript
|
|
99
|
-
* const parser = new DOMParser();
|
|
100
|
-
* const dom = parser.parseFromString(bookmarkHtml, "text/html");
|
|
101
|
-
* const tree = BookmarksTree.fromDOM(dom);
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
static fromDOM(dom) {
|
|
105
|
-
const tree = new BookmarksTree();
|
|
106
|
-
const document = dom;
|
|
107
|
-
const processElement = (element, currentTree) => {
|
|
108
|
-
const children = Array.from(element.children);
|
|
109
|
-
for (let i = 0; i < children.length; i++) {
|
|
110
|
-
const child = children[i];
|
|
111
|
-
if (child.tagName === "DT") {
|
|
112
|
-
const h3 = child.querySelector("h3");
|
|
113
|
-
const link = child.querySelector("a");
|
|
114
|
-
if (h3) {
|
|
115
|
-
// フォルダの場合
|
|
116
|
-
const folderName = h3.textContent?.trim() || "";
|
|
117
|
-
if (folderName) {
|
|
118
|
-
const folderTree = new BookmarksTree();
|
|
119
|
-
currentTree.set(folderName, folderTree);
|
|
120
|
-
processElement(child, folderTree);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
else if (link) {
|
|
124
|
-
// リンクの場合
|
|
125
|
-
const href = link.getAttribute("href");
|
|
126
|
-
const title = link.textContent?.trim() || "";
|
|
127
|
-
if (href && title) {
|
|
128
|
-
currentTree.set(title, href);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
else if (child.tagName === "DL") {
|
|
133
|
-
// ネストしたDLタグの場合も処理
|
|
134
|
-
processElement(child, currentTree);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
// HTMLのBODY全体から処理を開始
|
|
139
|
-
const body = document.body;
|
|
140
|
-
if (body) {
|
|
141
|
-
processElement(body, tree);
|
|
142
|
-
}
|
|
143
|
-
return tree;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Converts the BookmarksTree to an HTML document
|
|
147
|
-
*
|
|
148
|
-
* Generates an HTML document in Netscape Bookmark format.
|
|
149
|
-
*
|
|
150
|
-
* @returns HTML document in Netscape Bookmark format
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* ```typescript
|
|
154
|
-
* const tree = new BookmarksTree();
|
|
155
|
-
* tree.set("Google", "https://google.com");
|
|
156
|
-
* const dom = tree.toDOM();
|
|
157
|
-
* ```
|
|
158
|
-
*/
|
|
159
|
-
toDOM() {
|
|
160
|
-
return new DOMParser().parseFromString(this.HTMLText, "text/html");
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Gets the BookmarksTree as an HTML string in Netscape Bookmark format
|
|
164
|
-
*
|
|
165
|
-
* Generates a complete HTML document string including DOCTYPE, metadata, and body
|
|
166
|
-
* in Netscape Bookmark format.
|
|
167
|
-
*
|
|
168
|
-
* @returns HTML string in Netscape Bookmark format
|
|
169
|
-
*
|
|
170
|
-
* @example
|
|
171
|
-
* ```typescript
|
|
172
|
-
* const tree = new BookmarksTree();
|
|
173
|
-
* tree.set("Google", "https://google.com");
|
|
174
|
-
* const html = tree.HTMLText;
|
|
175
|
-
* console.log(html); // <!DOCTYPE NETSCAPE-Bookmark-file-1>...
|
|
176
|
-
* ```
|
|
177
|
-
*/
|
|
178
|
-
get HTMLText() {
|
|
179
|
-
const escapeHtml = (text) => {
|
|
180
|
-
return text
|
|
181
|
-
.replace(/&/g, "&")
|
|
182
|
-
.replace(/</g, "<")
|
|
183
|
-
.replace(/>/g, ">")
|
|
184
|
-
.replace(/"/g, """)
|
|
185
|
-
.replace(/'/g, "'");
|
|
186
|
-
};
|
|
187
|
-
const createBookmarkList = (tree, indent = "") => {
|
|
188
|
-
let html = `${indent}<DL><p>\n`;
|
|
189
|
-
for (const [key, value] of tree.entries()) {
|
|
190
|
-
if (typeof value === "string") {
|
|
191
|
-
// ブックマークの場合: <DT><A HREF="url">タイトル</A>
|
|
192
|
-
html += `${indent} <DT><A HREF="${escapeHtml(value)}">${escapeHtml(key)}</A>\n`;
|
|
193
|
-
}
|
|
194
|
-
else if (value instanceof BookmarksTree) {
|
|
195
|
-
// フォルダの場合: <DT><H3>フォルダ名</H3>
|
|
196
|
-
html += `${indent} <DT><H3>${escapeHtml(key)}</H3>\n`;
|
|
197
|
-
html += createBookmarkList(value, indent + " ");
|
|
198
|
-
html += `${indent} </DL><p>\n`;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
if (indent === "") {
|
|
202
|
-
// ルートレベルの場合は閉じタグを追加
|
|
203
|
-
html += `</DL>\n`;
|
|
204
|
-
}
|
|
205
|
-
return html;
|
|
206
|
-
};
|
|
207
|
-
const htmlTemplate = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
208
|
-
<HTML>
|
|
209
|
-
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
|
|
210
|
-
<TITLE>Bookmark</TITLE>
|
|
211
|
-
<H1>Bookmark</H1>
|
|
212
|
-
<BODY>
|
|
213
|
-
${createBookmarkList(this)}</BODY>
|
|
214
|
-
</HTML>`;
|
|
215
|
-
return htmlTemplate;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/BookmarksTree/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
|
package/esm/src/deps.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 grakeice
|
|
3
|
-
*
|
|
4
|
-
* This software is released under the MIT License.
|
|
5
|
-
* https://opensource.org/licenses/MIT
|
|
6
|
-
*/
|
|
7
|
-
export { DOMParser } from "../deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.js";
|
|
8
|
-
export type { Element, HTMLDocument } from "../deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.js";
|
|
9
|
-
//# sourceMappingURL=deps.d.ts.map
|
package/esm/src/deps.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deps.d.ts","sourceRoot":"","sources":["../../src/src/deps.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yDAAyD,CAAC;AACpF,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,yDAAyD,CAAC"}
|
package/esm/src/deps.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 grakeice
|
|
3
|
-
*
|
|
4
|
-
* This software is released under the MIT License.
|
|
5
|
-
* https://opensource.org/licenses/MIT
|
|
6
|
-
*/
|
|
7
|
-
import { BookmarksTree } from "../BookmarksTree/index.js";
|
|
8
|
-
/**
|
|
9
|
-
* A parser for Netscape Bookmark format files
|
|
10
|
-
*
|
|
11
|
-
* This class provides static methods to parse Netscape Bookmark format HTML strings
|
|
12
|
-
* and convert them into BookmarksTree instances for easier manipulation.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
17
|
-
* <HTML>
|
|
18
|
-
* <BODY>
|
|
19
|
-
* <DL><p>
|
|
20
|
-
* <DT><A HREF="https://google.com">Google</A>
|
|
21
|
-
* <DT><H3>Development</H3>
|
|
22
|
-
* <DL><p>
|
|
23
|
-
* <DT><A HREF="https://github.com">GitHub</A>
|
|
24
|
-
* </DL><p>
|
|
25
|
-
* </DL>
|
|
26
|
-
* </BODY>
|
|
27
|
-
* </HTML>`;
|
|
28
|
-
*
|
|
29
|
-
* const tree = BookmarksParser.parse(bookmarkHtml);
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export declare class BookmarksParser {
|
|
33
|
-
/**
|
|
34
|
-
* Parses a Netscape Bookmark format HTML string into a BookmarksTree
|
|
35
|
-
*
|
|
36
|
-
* Takes an HTML string in Netscape Bookmark format and converts it into a structured
|
|
37
|
-
* BookmarksTree that preserves the hierarchical organization of folders and bookmarks.
|
|
38
|
-
*
|
|
39
|
-
* @param data The HTML string in Netscape Bookmark format to parse
|
|
40
|
-
* @returns A BookmarksTree representing the parsed bookmark structure
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```typescript
|
|
44
|
-
* const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
45
|
-
* <HTML>
|
|
46
|
-
* <BODY>
|
|
47
|
-
* <DL><p>
|
|
48
|
-
* <DT><A HREF="https://google.com">Google</A>
|
|
49
|
-
* <DT><H3>Development</H3>
|
|
50
|
-
* <DL><p>
|
|
51
|
-
* <DT><A HREF="https://github.com">GitHub</A>
|
|
52
|
-
* </DL><p>
|
|
53
|
-
* </DL>
|
|
54
|
-
* </BODY>
|
|
55
|
-
* </HTML>`;
|
|
56
|
-
*
|
|
57
|
-
* const tree = BookmarksParser.parse(bookmarkHtml);
|
|
58
|
-
* console.log(tree.get("Google")); // "https://google.com"
|
|
59
|
-
*
|
|
60
|
-
* const folder = tree.get("Development");
|
|
61
|
-
* console.log(folder.get("GitHub")); // "https://github.com"
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
static parse(data: string): BookmarksTree;
|
|
65
|
-
}
|
|
66
|
-
//# sourceMappingURL=BookmarksParser.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BookmarksParser.d.ts","sourceRoot":"","sources":["../../../../src/src/web/BookmarksParser/BookmarksParser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,eAAe;IAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa;CAKzC"}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 grakeice
|
|
3
|
-
*
|
|
4
|
-
* This software is released under the MIT License.
|
|
5
|
-
* https://opensource.org/licenses/MIT
|
|
6
|
-
*/
|
|
7
|
-
import { DOMParser } from "../deps.js";
|
|
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
|
-
*/
|
|
33
|
-
export class BookmarksParser {
|
|
34
|
-
/**
|
|
35
|
-
* Parses a Netscape Bookmark format HTML string into a BookmarksTree
|
|
36
|
-
*
|
|
37
|
-
* Takes an HTML string in Netscape Bookmark format and converts it into a structured
|
|
38
|
-
* BookmarksTree that preserves the hierarchical organization of folders and bookmarks.
|
|
39
|
-
*
|
|
40
|
-
* @param data The HTML string in Netscape Bookmark format to parse
|
|
41
|
-
* @returns A BookmarksTree representing the parsed bookmark structure
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```typescript
|
|
45
|
-
* const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
46
|
-
* <HTML>
|
|
47
|
-
* <BODY>
|
|
48
|
-
* <DL><p>
|
|
49
|
-
* <DT><A HREF="https://google.com">Google</A>
|
|
50
|
-
* <DT><H3>Development</H3>
|
|
51
|
-
* <DL><p>
|
|
52
|
-
* <DT><A HREF="https://github.com">GitHub</A>
|
|
53
|
-
* </DL><p>
|
|
54
|
-
* </DL>
|
|
55
|
-
* </BODY>
|
|
56
|
-
* </HTML>`;
|
|
57
|
-
*
|
|
58
|
-
* const tree = BookmarksParser.parse(bookmarkHtml);
|
|
59
|
-
* console.log(tree.get("Google")); // "https://google.com"
|
|
60
|
-
*
|
|
61
|
-
* const folder = tree.get("Development");
|
|
62
|
-
* console.log(folder.get("GitHub")); // "https://github.com"
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
static parse(data) {
|
|
66
|
-
const dom = new DOMParser().parseFromString(data, "text/html");
|
|
67
|
-
const tree = BookmarksTree.fromDOM(dom);
|
|
68
|
-
return tree;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/web/BookmarksParser/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 grakeice
|
|
3
|
-
*
|
|
4
|
-
* This software is released under the MIT License.
|
|
5
|
-
* https://opensource.org/licenses/MIT
|
|
6
|
-
*/
|
|
7
|
-
import { type HTMLDocument } from "../deps.js";
|
|
8
|
-
/**
|
|
9
|
-
* A class representing a bookmark tree in Netscape Bookmark format
|
|
10
|
-
*
|
|
11
|
-
* This class extends Map and manages folders (BookmarksTree) and bookmarks (URL strings)
|
|
12
|
-
* in a hierarchical structure.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* const tree = new BookmarksTree();
|
|
17
|
-
* tree.set("Google", "https://google.com");
|
|
18
|
-
*
|
|
19
|
-
* const folder = new BookmarksTree();
|
|
20
|
-
* folder.set("GitHub", "https://github.com");
|
|
21
|
-
* tree.set("Development", folder);
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export declare class BookmarksTree extends Map<string, string | BookmarksTree> {
|
|
25
|
-
/**
|
|
26
|
-
* Creates a new BookmarksTree instance
|
|
27
|
-
*/
|
|
28
|
-
constructor();
|
|
29
|
-
/**
|
|
30
|
-
* Converts the BookmarksTree to a JSON object
|
|
31
|
-
*
|
|
32
|
-
* Folders are recursively converted to objects, and bookmarks are preserved as strings.
|
|
33
|
-
*
|
|
34
|
-
* @returns JSON object representation of the bookmark data
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* const tree = new BookmarksTree();
|
|
39
|
-
* tree.set("Google", "https://google.com");
|
|
40
|
-
* const json = tree.toJSON();
|
|
41
|
-
* // { "Google": "https://google.com" }
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
toJSON(): Record<string, unknown>;
|
|
45
|
-
/**
|
|
46
|
-
* Creates a BookmarksTree from a JSON object
|
|
47
|
-
*
|
|
48
|
-
* String properties are treated as bookmarks, and object properties are
|
|
49
|
-
* recursively processed as folders.
|
|
50
|
-
*
|
|
51
|
-
* @param json The source JSON object to convert
|
|
52
|
-
* @returns A new BookmarksTree instance
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* const json = { "Google": "https://google.com", "Development": { "GitHub": "https://github.com" } };
|
|
57
|
-
* const tree = BookmarksTree.fromJSON(json);
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
static fromJSON(json: Record<string, unknown>): BookmarksTree;
|
|
61
|
-
/**
|
|
62
|
-
* Creates a BookmarksTree from an HTML document (Netscape Bookmark format)
|
|
63
|
-
*
|
|
64
|
-
* Parses Netscape Bookmark format HTML and generates a BookmarksTree that preserves
|
|
65
|
-
* the hierarchical structure. H3 elements within DT elements are treated as folders,
|
|
66
|
-
* and A elements are treated as bookmarks.
|
|
67
|
-
*
|
|
68
|
-
* @param dom The HTML document to parse
|
|
69
|
-
* @returns A new BookmarksTree instance
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```typescript
|
|
73
|
-
* const parser = new DOMParser();
|
|
74
|
-
* const dom = parser.parseFromString(bookmarkHtml, "text/html");
|
|
75
|
-
* const tree = BookmarksTree.fromDOM(dom);
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
static fromDOM(dom: HTMLDocument): BookmarksTree;
|
|
79
|
-
/**
|
|
80
|
-
* Converts the BookmarksTree to an HTML document
|
|
81
|
-
*
|
|
82
|
-
* Generates an HTML document in Netscape Bookmark format.
|
|
83
|
-
*
|
|
84
|
-
* @returns HTML document in Netscape Bookmark format
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```typescript
|
|
88
|
-
* const tree = new BookmarksTree();
|
|
89
|
-
* tree.set("Google", "https://google.com");
|
|
90
|
-
* const dom = tree.toDOM();
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
toDOM(): HTMLDocument;
|
|
94
|
-
/**
|
|
95
|
-
* Gets the BookmarksTree as an HTML string in Netscape Bookmark format
|
|
96
|
-
*
|
|
97
|
-
* Generates a complete HTML document string including DOCTYPE, metadata, and body
|
|
98
|
-
* in Netscape Bookmark format.
|
|
99
|
-
*
|
|
100
|
-
* @returns HTML string in Netscape Bookmark format
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
104
|
-
* const tree = new BookmarksTree();
|
|
105
|
-
* tree.set("Google", "https://google.com");
|
|
106
|
-
* const html = tree.HTMLText;
|
|
107
|
-
* console.log(html); // <!DOCTYPE NETSCAPE-Bookmark-file-1>...
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
|
-
get HTMLText(): string;
|
|
111
|
-
}
|
|
112
|
-
//# sourceMappingURL=BookmarksTree.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BookmarksTree.d.ts","sourceRoot":"","sources":["../../../../src/src/web/BookmarksTree/BookmarksTree.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAA2B,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAExE;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,aAAc,SAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IACrE;;OAEG;;IAKH;;;;;;;;;;;;;;OAcG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAcjC;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa;IAmB7D;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,GAAG,aAAa;IA8ChD;;;;;;;;;;;;;OAaG;IACH,KAAK,IAAI,YAAY;IAIrB;;;;;;;;;;;;;;;OAeG;IACH,IAAI,QAAQ,IAAI,MAAM,CA+CrB;CACD"}
|