netscape-bookmark-parser 1.1.4 → 1.2.2
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 +108 -98
- package/README.md +108 -98
- package/dist/index.d.ts +237 -0
- package/dist/index.js +347 -0
- package/dist/index.js.map +1 -0
- package/dist/web.d.ts +239 -0
- package/dist/web.js +340 -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 -130
- package/esm/src/BookmarksParser/BookmarksParser.d.ts.map +0 -1
- package/esm/src/BookmarksParser/BookmarksParser.js +0 -142
- 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 -118
- package/esm/src/BookmarksTree/BookmarksTree.d.ts.map +0 -1
- package/esm/src/BookmarksTree/BookmarksTree.js +0 -225
- 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 -130
- package/esm/src/web/BookmarksParser/BookmarksParser.d.ts.map +0 -1
- package/esm/src/web/BookmarksParser/BookmarksParser.js +0 -142
- 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 -118
- package/esm/src/web/BookmarksTree/BookmarksTree.d.ts.map +0 -1
- package/esm/src/web/BookmarksTree/BookmarksTree.js +0 -225
- 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
package/dist/index.js
ADDED
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import { DOMParser } from "@b-fuze/deno-dom";
|
|
2
|
+
//#region src/dom.ts
|
|
3
|
+
let DOMParser$1 = globalThis.DOMParser;
|
|
4
|
+
const setDOMParser = (parser) => {
|
|
5
|
+
DOMParser$1 = parser;
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/node-dom.ts
|
|
9
|
+
/**
|
|
10
|
+
* Copyright (c) 2025-2026 kurage(@umitsukidev)
|
|
11
|
+
*
|
|
12
|
+
* This software is released under the MIT License.
|
|
13
|
+
* https://opensource.org/licenses/MIT
|
|
14
|
+
*/
|
|
15
|
+
setDOMParser(DOMParser);
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/BookmarksTree/BookmarksTree.ts
|
|
18
|
+
/**
|
|
19
|
+
* Copyright (c) 2025-2026 kurage(@umitsukidev)
|
|
20
|
+
*
|
|
21
|
+
* This software is released under the MIT License.
|
|
22
|
+
* https://opensource.org/licenses/MIT
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* A class representing a bookmark tree in Netscape Bookmark format
|
|
26
|
+
*
|
|
27
|
+
* This class extends Map and manages folders (BookmarksTree) and bookmarks (URL strings)
|
|
28
|
+
* in a hierarchical structure.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const tree = new BookmarksTree();
|
|
33
|
+
* tree.set("Google", "https://google.com");
|
|
34
|
+
*
|
|
35
|
+
* const folder = new BookmarksTree();
|
|
36
|
+
* folder.set("GitHub", "https://github.com");
|
|
37
|
+
* tree.set("Development", folder);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
var BookmarksTree = class BookmarksTree extends Map {
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new BookmarksTree instance
|
|
43
|
+
*/
|
|
44
|
+
constructor() {
|
|
45
|
+
super();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Converts the BookmarksTree to a JSON object
|
|
49
|
+
*
|
|
50
|
+
* Folders are recursively converted to objects, and bookmarks are preserved as strings.
|
|
51
|
+
*
|
|
52
|
+
* @returns JSON object representation of the bookmark data
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const tree = new BookmarksTree();
|
|
57
|
+
* tree.set("Google", "https://google.com");
|
|
58
|
+
* const json = tree.toJSON();
|
|
59
|
+
* // { "Google": "https://google.com" }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
toJSON() {
|
|
63
|
+
const json = {};
|
|
64
|
+
for (const [key, value] of this.entries()) if (typeof value === "string") json[key] = value;
|
|
65
|
+
else if (value instanceof BookmarksTree) json[key] = value.toJSON();
|
|
66
|
+
return json;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creates a BookmarksTree from a JSON object
|
|
70
|
+
*
|
|
71
|
+
* String properties are treated as bookmarks, and object properties are
|
|
72
|
+
* recursively processed as folders.
|
|
73
|
+
*
|
|
74
|
+
* @param json The source JSON object to convert
|
|
75
|
+
* @returns A new BookmarksTree instance
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const json = { "Google": "https://google.com", "Development": { "GitHub": "https://github.com" } };
|
|
80
|
+
* const tree = BookmarksTree.fromJSON(json);
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
static fromJSON(json) {
|
|
84
|
+
const tree = new BookmarksTree();
|
|
85
|
+
if (typeof json === "object" && json !== null) {
|
|
86
|
+
for (const [key, value] of Object.entries(json)) if (typeof value === "string") tree.set(key, value);
|
|
87
|
+
else if (typeof value === "object" && value !== null) tree.set(key, BookmarksTree.fromJSON(value));
|
|
88
|
+
}
|
|
89
|
+
return tree;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Creates a BookmarksTree from an HTML document (Netscape Bookmark format)
|
|
93
|
+
*
|
|
94
|
+
* Parses Netscape Bookmark format HTML and generates a BookmarksTree that preserves
|
|
95
|
+
* the hierarchical structure. H3 elements within DT elements are treated as folders,
|
|
96
|
+
* and A elements are treated as bookmarks.
|
|
97
|
+
*
|
|
98
|
+
* @param dom The HTML document to parse
|
|
99
|
+
* @returns A new BookmarksTree instance
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* const parser = new DOMParser();
|
|
104
|
+
* const dom = parser.parseFromString(bookmarkHtml, "text/html");
|
|
105
|
+
* const tree = BookmarksTree.fromDOM(dom);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
static fromDOM(dom) {
|
|
109
|
+
const tree = new BookmarksTree();
|
|
110
|
+
const document = dom;
|
|
111
|
+
const processElement = (element, currentTree) => {
|
|
112
|
+
const children = Array.from(element.children);
|
|
113
|
+
for (let i = 0; i < children.length; i++) {
|
|
114
|
+
const child = children[i];
|
|
115
|
+
if (child.tagName === "DT") {
|
|
116
|
+
const h3 = child.querySelector("h3");
|
|
117
|
+
const link = child.querySelector("a");
|
|
118
|
+
if (h3) {
|
|
119
|
+
const folderName = h3.textContent?.trim() || "";
|
|
120
|
+
if (folderName) {
|
|
121
|
+
const folderTree = new BookmarksTree();
|
|
122
|
+
currentTree.set(folderName, folderTree);
|
|
123
|
+
processElement(child, folderTree);
|
|
124
|
+
}
|
|
125
|
+
} else if (link) {
|
|
126
|
+
const href = link.getAttribute("href");
|
|
127
|
+
const title = link.textContent?.trim() || "";
|
|
128
|
+
if (href && title) currentTree.set(title, href);
|
|
129
|
+
}
|
|
130
|
+
} else if (child.tagName === "DL") processElement(child, currentTree);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const body = document.body;
|
|
134
|
+
if (body) processElement(body, tree);
|
|
135
|
+
return tree;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Converts the BookmarksTree to an HTML document
|
|
139
|
+
*
|
|
140
|
+
* Generates an HTML document in Netscape Bookmark format.
|
|
141
|
+
*
|
|
142
|
+
* @returns HTML document in Netscape Bookmark format
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const tree = new BookmarksTree();
|
|
147
|
+
* tree.set("Google", "https://google.com");
|
|
148
|
+
* const dom = tree.toDOM();
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
toDOM() {
|
|
152
|
+
return new DOMParser$1().parseFromString(this.HTMLString, "text/html");
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Gets the BookmarksTree as an HTML string in Netscape Bookmark format
|
|
156
|
+
*
|
|
157
|
+
* Generates a complete HTML document string including DOCTYPE, metadata, and body
|
|
158
|
+
* in Netscape Bookmark format.
|
|
159
|
+
*
|
|
160
|
+
* @returns HTML string in Netscape Bookmark format
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const tree = new BookmarksTree();
|
|
165
|
+
* tree.set("Google", "https://google.com");
|
|
166
|
+
* const html = tree.HTMLString;
|
|
167
|
+
* console.log(html); // <!DOCTYPE NETSCAPE-Bookmark-file-1>...
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
get HTMLString() {
|
|
171
|
+
const escapeHtml = (text) => {
|
|
172
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
173
|
+
};
|
|
174
|
+
const createBookmarkList = (tree, indent = "") => {
|
|
175
|
+
let html = `${indent}<DL><p>\n`;
|
|
176
|
+
for (const [key, value] of tree.entries()) if (typeof value === "string") html += `${indent} <DT><A HREF="${escapeHtml(value)}">${escapeHtml(key)}</A>\n`;
|
|
177
|
+
else if (value instanceof BookmarksTree) {
|
|
178
|
+
html += `${indent} <DT><H3>${escapeHtml(key)}</H3>\n`;
|
|
179
|
+
html += createBookmarkList(value, indent + " ");
|
|
180
|
+
html += `${indent} </DL><p>\n`;
|
|
181
|
+
}
|
|
182
|
+
if (indent === "") html += `</DL>\n`;
|
|
183
|
+
return html;
|
|
184
|
+
};
|
|
185
|
+
return `<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
186
|
+
<HTML>
|
|
187
|
+
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
|
|
188
|
+
<TITLE>Bookmark</TITLE>
|
|
189
|
+
<H1>Bookmark</H1>
|
|
190
|
+
<BODY>
|
|
191
|
+
${createBookmarkList(this)}</BODY>
|
|
192
|
+
</HTML>`;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* @deprecated Use {@link HTMLString} instead.
|
|
196
|
+
*
|
|
197
|
+
* Gets the BookmarksTree as an HTML string in Netscape Bookmark format.
|
|
198
|
+
*/
|
|
199
|
+
get HTMLText() {
|
|
200
|
+
return this.HTMLString;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/BookmarksParser/BookmarksParser.ts
|
|
205
|
+
/**
|
|
206
|
+
* Copyright (c) 2025-2026 kurage(@umitsukidev)
|
|
207
|
+
*
|
|
208
|
+
* This software is released under the MIT License.
|
|
209
|
+
* https://opensource.org/licenses/MIT
|
|
210
|
+
*/
|
|
211
|
+
/**
|
|
212
|
+
* A parser for Netscape Bookmark format files
|
|
213
|
+
*
|
|
214
|
+
* This class provides static methods to parse Netscape Bookmark format HTML strings
|
|
215
|
+
* and convert them into BookmarksTree instances for easier manipulation.
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
220
|
+
* <HTML>
|
|
221
|
+
* <BODY>
|
|
222
|
+
* <DL><p>
|
|
223
|
+
* <DT><A HREF="https://google.com">Google</A>
|
|
224
|
+
* <DT><H3>Development</H3>
|
|
225
|
+
* <DL><p>
|
|
226
|
+
* <DT><A HREF="https://github.com">GitHub</A>
|
|
227
|
+
* </DL><p>
|
|
228
|
+
* </DL>
|
|
229
|
+
* </BODY>
|
|
230
|
+
* </HTML>`;
|
|
231
|
+
*
|
|
232
|
+
* const tree = BookmarksParser.parse(bookmarkHtml);
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
var BookmarksParser = class {
|
|
236
|
+
/**
|
|
237
|
+
* Alias for the {@link parseFromHTMLString} method.
|
|
238
|
+
*
|
|
239
|
+
* @param htmlString HTML string in Netscape Bookmark format
|
|
240
|
+
* @returns The parsed BookmarksTree
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
245
|
+
* <HTML>
|
|
246
|
+
* <BODY>
|
|
247
|
+
* <DL><p>
|
|
248
|
+
* <DT><A HREF="https://google.com">Google</A>
|
|
249
|
+
* <DT><H3>Development</H3>
|
|
250
|
+
* <DL><p>
|
|
251
|
+
* <DT><A HREF="https://github.com">GitHub</A>
|
|
252
|
+
* </DL><p>
|
|
253
|
+
* </DL>
|
|
254
|
+
* </BODY>
|
|
255
|
+
* </HTML>`;
|
|
256
|
+
*
|
|
257
|
+
* const tree = BookmarksParser.parse(bookmarkHtml);
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
static parse(htmlString) {
|
|
261
|
+
return this.parseFromHTMLString(htmlString);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Parses a Netscape Bookmark format HTML string and returns a BookmarksTree.
|
|
265
|
+
*
|
|
266
|
+
* @param htmlString HTML string in Netscape Bookmark format
|
|
267
|
+
* @returns The parsed BookmarksTree
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```typescript
|
|
271
|
+
* const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
272
|
+
* <HTML>
|
|
273
|
+
* <BODY>
|
|
274
|
+
* <DL><p>
|
|
275
|
+
* <DT><A HREF="https://google.com">Google</A>
|
|
276
|
+
* <DT><H3>Development</H3>
|
|
277
|
+
* <DL><p>
|
|
278
|
+
* <DT><A HREF="https://github.com">GitHub</A>
|
|
279
|
+
* </DL><p>
|
|
280
|
+
* </DL>
|
|
281
|
+
* </BODY>
|
|
282
|
+
* </HTML>`;
|
|
283
|
+
*
|
|
284
|
+
* const tree = BookmarksParser.parseFromHTMLString(bookmarkHtml);
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
static parseFromHTMLString(htmlString) {
|
|
288
|
+
const dom = new DOMParser$1().parseFromString(htmlString, "text/html");
|
|
289
|
+
return BookmarksTree.fromDOM(dom);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Creates a BookmarksTree from an existing HTMLDocument.
|
|
293
|
+
*
|
|
294
|
+
* This is an alias for {@link BookmarksTree.fromDOM}.
|
|
295
|
+
*
|
|
296
|
+
* Use this when you already have a parsed HTMLDocument and want to convert it to a BookmarksTree.
|
|
297
|
+
*
|
|
298
|
+
* @param dom An HTMLDocument instance
|
|
299
|
+
* @returns The parsed BookmarksTree
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```typescript
|
|
303
|
+
* const dom = new DOMParser().parseFromString(bookmarkHtml, "text/html");
|
|
304
|
+
* const tree = BookmarksParser.parseFromDOM(dom);
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
static parseFromDOM(dom) {
|
|
308
|
+
return BookmarksTree.fromDOM(dom);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Parses a JSON string and returns a BookmarksTree.
|
|
312
|
+
*
|
|
313
|
+
* @param jsonString JSON string representing the bookmark structure
|
|
314
|
+
* @returns The parsed BookmarksTree
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```typescript
|
|
318
|
+
* const json = '{"Google":"https://google.com","Development":{"GitHub":"https://github.com"}}';
|
|
319
|
+
* const tree = BookmarksParser.parseFromJSONString(json);
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
static parseFromJSONString(jsonString) {
|
|
323
|
+
const obj = JSON.parse(jsonString);
|
|
324
|
+
return BookmarksTree.fromJSON(obj);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Parses a JSON object and returns a BookmarksTree.
|
|
328
|
+
*
|
|
329
|
+
* This is an alias for {@link BookmarksTree.fromJSON}.
|
|
330
|
+
*
|
|
331
|
+
* @param jsonObj JSON object representing the bookmark structure
|
|
332
|
+
* @returns The parsed BookmarksTree
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```typescript
|
|
336
|
+
* const obj = { "Google": "https://google.com", "Development": { "GitHub": "https://github.com" } };
|
|
337
|
+
* const tree = BookmarksParser.parseFromJSON(obj);
|
|
338
|
+
* ```
|
|
339
|
+
*/
|
|
340
|
+
static parseFromJSON(jsonObj) {
|
|
341
|
+
return BookmarksTree.fromJSON(jsonObj);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
//#endregion
|
|
345
|
+
export { BookmarksParser, BookmarksTree };
|
|
346
|
+
|
|
347
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["DOMParser","NodeDOMParser","DOMParser","DOMParser"],"sources":["../src/dom.ts","../src/node-dom.ts","../src/BookmarksTree/BookmarksTree.ts","../src/BookmarksParser/BookmarksParser.ts"],"sourcesContent":["/**\n * Copyright (c) 2025-2026 kurage(@umitsukidev)\n *\n * This software is released under the MIT License.\n * https://opensource.org/licenses/MIT\n */\n\nimport type { DOMParser as NodeDOMParser } from \"@b-fuze/deno-dom\";\n\nexport let DOMParser: typeof NodeDOMParser =\n\tglobalThis.DOMParser as unknown as typeof NodeDOMParser;\n\nexport const setDOMParser = (parser: typeof NodeDOMParser): void => {\n\tDOMParser = parser;\n};\n","/**\n * Copyright (c) 2025-2026 kurage(@umitsukidev)\n *\n * This software is released under the MIT License.\n * https://opensource.org/licenses/MIT\n */\n\nimport { DOMParser as NodeDOMParser } from \"@b-fuze/deno-dom\";\nimport { setDOMParser } from \"./dom.ts\";\n\nsetDOMParser(NodeDOMParser);\n","/**\n * Copyright (c) 2025-2026 kurage(@umitsukidev)\n *\n * This software is released under the MIT License.\n * https://opensource.org/licenses/MIT\n */\n\nimport { DOMParser } from \"../dom.ts\";\nimport type { Element, HTMLDocument } from \"#dom-types\";\n\n/**\n * A class representing a bookmark tree in Netscape Bookmark format\n *\n * This class extends Map and manages folders (BookmarksTree) and bookmarks (URL strings)\n * in a hierarchical structure.\n *\n * @example\n * ```typescript\n * const tree = new BookmarksTree();\n * tree.set(\"Google\", \"https://google.com\");\n *\n * const folder = new BookmarksTree();\n * folder.set(\"GitHub\", \"https://github.com\");\n * tree.set(\"Development\", folder);\n * ```\n */\nexport class BookmarksTree extends Map<string, string | BookmarksTree> {\n\t/**\n\t * Creates a new BookmarksTree instance\n\t */\n\tconstructor() {\n\t\tsuper();\n\t}\n\n\t/**\n\t * Converts the BookmarksTree to a JSON object\n\t *\n\t * Folders are recursively converted to objects, and bookmarks are preserved as strings.\n\t *\n\t * @returns JSON object representation of the bookmark data\n\t *\n\t * @example\n\t * ```typescript\n\t * const tree = new BookmarksTree();\n\t * tree.set(\"Google\", \"https://google.com\");\n\t * const json = tree.toJSON();\n\t * // { \"Google\": \"https://google.com\" }\n\t * ```\n\t */\n\ttoJSON(): Record<string, unknown> {\n\t\tconst json: Record<string, unknown> = {};\n\n\t\tfor (const [key, value] of this.entries()) {\n\t\t\tif (typeof value === \"string\") {\n\t\t\t\tjson[key] = value;\n\t\t\t} else if (value instanceof BookmarksTree) {\n\t\t\t\tjson[key] = value.toJSON();\n\t\t\t}\n\t\t}\n\n\t\treturn json;\n\t}\n\n\t/**\n\t * Creates a BookmarksTree from a JSON object\n\t *\n\t * String properties are treated as bookmarks, and object properties are\n\t * recursively processed as folders.\n\t *\n\t * @param json The source JSON object to convert\n\t * @returns A new BookmarksTree instance\n\t *\n\t * @example\n\t * ```typescript\n\t * const json = { \"Google\": \"https://google.com\", \"Development\": { \"GitHub\": \"https://github.com\" } };\n\t * const tree = BookmarksTree.fromJSON(json);\n\t * ```\n\t */\n\tstatic fromJSON(json: Record<string, unknown>): BookmarksTree {\n\t\tconst tree = new BookmarksTree();\n\n\t\tif (typeof json === \"object\" && json !== null) {\n\t\t\tfor (const [key, value] of Object.entries(json)) {\n\t\t\t\tif (typeof value === \"string\") {\n\t\t\t\t\ttree.set(key, value);\n\t\t\t\t} else if (typeof value === \"object\" && value !== null) {\n\t\t\t\t\ttree.set(key, BookmarksTree.fromJSON(value as Record<string, unknown>));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn tree;\n\t}\n\n\t/**\n\t * Creates a BookmarksTree from an HTML document (Netscape Bookmark format)\n\t *\n\t * Parses Netscape Bookmark format HTML and generates a BookmarksTree that preserves\n\t * the hierarchical structure. H3 elements within DT elements are treated as folders,\n\t * and A elements are treated as bookmarks.\n\t *\n\t * @param dom The HTML document to parse\n\t * @returns A new BookmarksTree instance\n\t *\n\t * @example\n\t * ```typescript\n\t * const parser = new DOMParser();\n\t * const dom = parser.parseFromString(bookmarkHtml, \"text/html\");\n\t * const tree = BookmarksTree.fromDOM(dom);\n\t * ```\n\t */\n\tstatic fromDOM(dom: HTMLDocument): BookmarksTree {\n\t\tconst tree = new BookmarksTree();\n\t\tconst document = dom;\n\n\t\tconst processElement = (element: Element, currentTree: BookmarksTree) => {\n\t\t\tconst children = Array.from(element.children) as Element[];\n\n\t\t\tfor (let i = 0; i < children.length; i++) {\n\t\t\t\tconst child = children[i];\n\n\t\t\t\tif (child.tagName === \"DT\") {\n\t\t\t\t\tconst h3 = child.querySelector(\"h3\");\n\t\t\t\t\tconst link = child.querySelector(\"a\");\n\n\t\t\t\t\tif (h3) {\n\t\t\t\t\t\t// フォルダの場合\n\t\t\t\t\t\tconst folderName = h3.textContent?.trim() || \"\";\n\t\t\t\t\t\tif (folderName) {\n\t\t\t\t\t\t\tconst folderTree = new BookmarksTree();\n\t\t\t\t\t\t\tcurrentTree.set(folderName, folderTree);\n\t\t\t\t\t\t\tprocessElement(child, folderTree);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (link) {\n\t\t\t\t\t\t// リンクの場合\n\t\t\t\t\t\tconst href = link.getAttribute(\"href\");\n\t\t\t\t\t\tconst title = link.textContent?.trim() || \"\";\n\t\t\t\t\t\tif (href && title) {\n\t\t\t\t\t\t\tcurrentTree.set(title, href);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else if (child.tagName === \"DL\") {\n\t\t\t\t\t// ネストしたDLタグの場合も処理\n\t\t\t\t\tprocessElement(child, currentTree);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\t// HTMLのBODY全体から処理を開始\n\t\tconst body = document.body;\n\t\tif (body) {\n\t\t\tprocessElement(body, tree);\n\t\t}\n\n\t\treturn tree;\n\t}\n\n\t/**\n\t * Converts the BookmarksTree to an HTML document\n\t *\n\t * Generates an HTML document in Netscape Bookmark format.\n\t *\n\t * @returns HTML document in Netscape Bookmark format\n\t *\n\t * @example\n\t * ```typescript\n\t * const tree = new BookmarksTree();\n\t * tree.set(\"Google\", \"https://google.com\");\n\t * const dom = tree.toDOM();\n\t * ```\n\t */\n\ttoDOM(): HTMLDocument {\n\t\treturn new DOMParser().parseFromString(this.HTMLString, \"text/html\");\n\t}\n\n\t/**\n\t * Gets the BookmarksTree as an HTML string in Netscape Bookmark format\n\t *\n\t * Generates a complete HTML document string including DOCTYPE, metadata, and body\n\t * in Netscape Bookmark format.\n\t *\n\t * @returns HTML string in Netscape Bookmark format\n\t *\n\t * @example\n\t * ```typescript\n\t * const tree = new BookmarksTree();\n\t * tree.set(\"Google\", \"https://google.com\");\n\t * const html = tree.HTMLString;\n\t * console.log(html); // <!DOCTYPE NETSCAPE-Bookmark-file-1>...\n\t * ```\n\t */\n\tget HTMLString(): string {\n\t\tconst escapeHtml = (text: string): string => {\n\t\t\treturn text\n\t\t\t\t.replace(/&/g, \"&\")\n\t\t\t\t.replace(/</g, \"<\")\n\t\t\t\t.replace(/>/g, \">\")\n\t\t\t\t.replace(/\"/g, \""\")\n\t\t\t\t.replace(/'/g, \"'\");\n\t\t};\n\n\t\tconst createBookmarkList = (tree: BookmarksTree, indent: string = \"\"): string => {\n\t\t\tlet html = `${indent}<DL><p>\\n`;\n\n\t\t\tfor (const [key, value] of tree.entries()) {\n\t\t\t\tif (typeof value === \"string\") {\n\t\t\t\t\t// ブックマークの場合: <DT><A HREF=\"url\">タイトル</A>\n\t\t\t\t\thtml += `${indent} <DT><A HREF=\"${escapeHtml(value)}\">${escapeHtml(key)}</A>\\n`;\n\t\t\t\t} else if (value instanceof BookmarksTree) {\n\t\t\t\t\t// フォルダの場合: <DT><H3>フォルダ名</H3>\n\t\t\t\t\thtml += `${indent} <DT><H3>${escapeHtml(key)}</H3>\\n`;\n\t\t\t\t\thtml += createBookmarkList(value, indent + \" \");\n\t\t\t\t\thtml += `${indent} </DL><p>\\n`;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (indent === \"\") {\n\t\t\t\t// ルートレベルの場合は閉じタグを追加\n\t\t\t\thtml += `</DL>\\n`;\n\t\t\t}\n\n\t\t\treturn html;\n\t\t};\n\n\t\tconst htmlTemplate = `<!DOCTYPE NETSCAPE-Bookmark-file-1>\n<HTML>\n<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">\n<TITLE>Bookmark</TITLE>\n<H1>Bookmark</H1>\n<BODY>\n${createBookmarkList(this)}</BODY>\n</HTML>`;\n\t\treturn htmlTemplate;\n\t}\n\n\t/**\n\t * @deprecated Use {@link HTMLString} instead.\n\t *\n\t * Gets the BookmarksTree as an HTML string in Netscape Bookmark format.\n\t */\n\tget HTMLText(): string {\n\t\treturn this.HTMLString;\n\t}\n}\n","/**\n * Copyright (c) 2025-2026 kurage(@umitsukidev)\n *\n * This software is released under the MIT License.\n * https://opensource.org/licenses/MIT\n */\n\nimport { DOMParser } from \"../dom.ts\";\nimport type { HTMLDocument } from \"#dom-types\";\nimport { BookmarksTree } from \"../BookmarksTree/index.ts\";\n\n/**\n * A parser for Netscape Bookmark format files\n *\n * This class provides static methods to parse Netscape Bookmark format HTML strings\n * and convert them into BookmarksTree instances for easier manipulation.\n *\n * @example\n * ```typescript\n * const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>\n * <HTML>\n * <BODY>\n * <DL><p>\n * <DT><A HREF=\"https://google.com\">Google</A>\n * <DT><H3>Development</H3>\n * <DL><p>\n * <DT><A HREF=\"https://github.com\">GitHub</A>\n * </DL><p>\n * </DL>\n * </BODY>\n * </HTML>`;\n *\n * const tree = BookmarksParser.parse(bookmarkHtml);\n * ```\n */\nexport class BookmarksParser {\n\t/**\n\t * Alias for the {@link parseFromHTMLString} method.\n\t *\n\t * @param htmlString HTML string in Netscape Bookmark format\n\t * @returns The parsed BookmarksTree\n\t *\n\t * @example\n\t * ```typescript\n\t * const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>\n\t * <HTML>\n\t * <BODY>\n\t * <DL><p>\n\t * <DT><A HREF=\"https://google.com\">Google</A>\n\t * <DT><H3>Development</H3>\n\t * <DL><p>\n\t * <DT><A HREF=\"https://github.com\">GitHub</A>\n\t * </DL><p>\n\t * </DL>\n\t * </BODY>\n\t * </HTML>`;\n\t *\n\t * const tree = BookmarksParser.parse(bookmarkHtml);\n\t * ```\n\t */\n\tstatic parse(htmlString: string): BookmarksTree {\n\t\treturn this.parseFromHTMLString(htmlString);\n\t}\n\n\t/**\n\t * Parses a Netscape Bookmark format HTML string and returns a BookmarksTree.\n\t *\n\t * @param htmlString HTML string in Netscape Bookmark format\n\t * @returns The parsed BookmarksTree\n\t *\n\t * @example\n\t * ```typescript\n\t * const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>\n\t * <HTML>\n\t * <BODY>\n\t * <DL><p>\n\t * <DT><A HREF=\"https://google.com\">Google</A>\n\t * <DT><H3>Development</H3>\n\t * <DL><p>\n\t * <DT><A HREF=\"https://github.com\">GitHub</A>\n\t * </DL><p>\n\t * </DL>\n\t * </BODY>\n\t * </HTML>`;\n\t *\n\t * const tree = BookmarksParser.parseFromHTMLString(bookmarkHtml);\n\t * ```\n\t */\n\tstatic parseFromHTMLString(htmlString: string): BookmarksTree {\n\t\tconst dom = new DOMParser().parseFromString(htmlString, \"text/html\");\n\t\tconst tree = BookmarksTree.fromDOM(dom);\n\t\treturn tree;\n\t}\n\n\t/**\n\t * Creates a BookmarksTree from an existing HTMLDocument.\n\t *\n\t * This is an alias for {@link BookmarksTree.fromDOM}.\n\t *\n\t * Use this when you already have a parsed HTMLDocument and want to convert it to a BookmarksTree.\n\t *\n\t * @param dom An HTMLDocument instance\n\t * @returns The parsed BookmarksTree\n\t *\n\t * @example\n\t * ```typescript\n\t * const dom = new DOMParser().parseFromString(bookmarkHtml, \"text/html\");\n\t * const tree = BookmarksParser.parseFromDOM(dom);\n\t * ```\n\t */\n\tstatic parseFromDOM(dom: HTMLDocument): BookmarksTree {\n\t\treturn BookmarksTree.fromDOM(dom);\n\t}\n\n\t/**\n\t * Parses a JSON string and returns a BookmarksTree.\n\t *\n\t * @param jsonString JSON string representing the bookmark structure\n\t * @returns The parsed BookmarksTree\n\t *\n\t * @example\n\t * ```typescript\n\t * const json = '{\"Google\":\"https://google.com\",\"Development\":{\"GitHub\":\"https://github.com\"}}';\n\t * const tree = BookmarksParser.parseFromJSONString(json);\n\t * ```\n\t */\n\tstatic parseFromJSONString(jsonString: string): BookmarksTree {\n\t\tconst obj = JSON.parse(jsonString);\n\t\treturn BookmarksTree.fromJSON(obj);\n\t}\n\n\t/**\n\t * Parses a JSON object and returns a BookmarksTree.\n\t *\n\t * This is an alias for {@link BookmarksTree.fromJSON}.\n\t *\n\t * @param jsonObj JSON object representing the bookmark structure\n\t * @returns The parsed BookmarksTree\n\t *\n\t * @example\n\t * ```typescript\n\t * const obj = { \"Google\": \"https://google.com\", \"Development\": { \"GitHub\": \"https://github.com\" } };\n\t * const tree = BookmarksParser.parseFromJSON(obj);\n\t * ```\n\t */\n\tstatic parseFromJSON(jsonObj: Record<string, unknown>): BookmarksTree {\n\t\treturn BookmarksTree.fromJSON(jsonObj);\n\t}\n}\n"],"mappings":"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"}
|
package/dist/web.d.ts
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
//#region src/web-dom-types.d.ts
|
|
2
|
+
type HTMLDocument = globalThis.HTMLDocument;
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region src/BookmarksTree/BookmarksTree.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* A class representing a bookmark tree in Netscape Bookmark format
|
|
7
|
+
*
|
|
8
|
+
* This class extends Map and manages folders (BookmarksTree) and bookmarks (URL strings)
|
|
9
|
+
* in a hierarchical structure.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const tree = new BookmarksTree();
|
|
14
|
+
* tree.set("Google", "https://google.com");
|
|
15
|
+
*
|
|
16
|
+
* const folder = new BookmarksTree();
|
|
17
|
+
* folder.set("GitHub", "https://github.com");
|
|
18
|
+
* tree.set("Development", folder);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare class BookmarksTree extends Map<string, string | BookmarksTree> {
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new BookmarksTree instance
|
|
24
|
+
*/
|
|
25
|
+
constructor();
|
|
26
|
+
/**
|
|
27
|
+
* Converts the BookmarksTree to a JSON object
|
|
28
|
+
*
|
|
29
|
+
* Folders are recursively converted to objects, and bookmarks are preserved as strings.
|
|
30
|
+
*
|
|
31
|
+
* @returns JSON object representation of the bookmark data
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const tree = new BookmarksTree();
|
|
36
|
+
* tree.set("Google", "https://google.com");
|
|
37
|
+
* const json = tree.toJSON();
|
|
38
|
+
* // { "Google": "https://google.com" }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
toJSON(): Record<string, unknown>;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a BookmarksTree from a JSON object
|
|
44
|
+
*
|
|
45
|
+
* String properties are treated as bookmarks, and object properties are
|
|
46
|
+
* recursively processed as folders.
|
|
47
|
+
*
|
|
48
|
+
* @param json The source JSON object to convert
|
|
49
|
+
* @returns A new BookmarksTree instance
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const json = { "Google": "https://google.com", "Development": { "GitHub": "https://github.com" } };
|
|
54
|
+
* const tree = BookmarksTree.fromJSON(json);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
static fromJSON(json: Record<string, unknown>): BookmarksTree;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a BookmarksTree from an HTML document (Netscape Bookmark format)
|
|
60
|
+
*
|
|
61
|
+
* Parses Netscape Bookmark format HTML and generates a BookmarksTree that preserves
|
|
62
|
+
* the hierarchical structure. H3 elements within DT elements are treated as folders,
|
|
63
|
+
* and A elements are treated as bookmarks.
|
|
64
|
+
*
|
|
65
|
+
* @param dom The HTML document to parse
|
|
66
|
+
* @returns A new BookmarksTree instance
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const parser = new DOMParser();
|
|
71
|
+
* const dom = parser.parseFromString(bookmarkHtml, "text/html");
|
|
72
|
+
* const tree = BookmarksTree.fromDOM(dom);
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
static fromDOM(dom: HTMLDocument): BookmarksTree;
|
|
76
|
+
/**
|
|
77
|
+
* Converts the BookmarksTree to an HTML document
|
|
78
|
+
*
|
|
79
|
+
* Generates an HTML document in Netscape Bookmark format.
|
|
80
|
+
*
|
|
81
|
+
* @returns HTML document in Netscape Bookmark format
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const tree = new BookmarksTree();
|
|
86
|
+
* tree.set("Google", "https://google.com");
|
|
87
|
+
* const dom = tree.toDOM();
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
toDOM(): HTMLDocument;
|
|
91
|
+
/**
|
|
92
|
+
* Gets the BookmarksTree as an HTML string in Netscape Bookmark format
|
|
93
|
+
*
|
|
94
|
+
* Generates a complete HTML document string including DOCTYPE, metadata, and body
|
|
95
|
+
* in Netscape Bookmark format.
|
|
96
|
+
*
|
|
97
|
+
* @returns HTML string in Netscape Bookmark format
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const tree = new BookmarksTree();
|
|
102
|
+
* tree.set("Google", "https://google.com");
|
|
103
|
+
* const html = tree.HTMLString;
|
|
104
|
+
* console.log(html); // <!DOCTYPE NETSCAPE-Bookmark-file-1>...
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
get HTMLString(): string;
|
|
108
|
+
/**
|
|
109
|
+
* @deprecated Use {@link HTMLString} instead.
|
|
110
|
+
*
|
|
111
|
+
* Gets the BookmarksTree as an HTML string in Netscape Bookmark format.
|
|
112
|
+
*/
|
|
113
|
+
get HTMLText(): string;
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/BookmarksParser/BookmarksParser.d.ts
|
|
117
|
+
/**
|
|
118
|
+
* A parser for Netscape Bookmark format files
|
|
119
|
+
*
|
|
120
|
+
* This class provides static methods to parse Netscape Bookmark format HTML strings
|
|
121
|
+
* and convert them into BookmarksTree instances for easier manipulation.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
126
|
+
* <HTML>
|
|
127
|
+
* <BODY>
|
|
128
|
+
* <DL><p>
|
|
129
|
+
* <DT><A HREF="https://google.com">Google</A>
|
|
130
|
+
* <DT><H3>Development</H3>
|
|
131
|
+
* <DL><p>
|
|
132
|
+
* <DT><A HREF="https://github.com">GitHub</A>
|
|
133
|
+
* </DL><p>
|
|
134
|
+
* </DL>
|
|
135
|
+
* </BODY>
|
|
136
|
+
* </HTML>`;
|
|
137
|
+
*
|
|
138
|
+
* const tree = BookmarksParser.parse(bookmarkHtml);
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export declare class BookmarksParser {
|
|
142
|
+
/**
|
|
143
|
+
* Alias for the {@link parseFromHTMLString} method.
|
|
144
|
+
*
|
|
145
|
+
* @param htmlString HTML string in Netscape Bookmark format
|
|
146
|
+
* @returns The parsed BookmarksTree
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
151
|
+
* <HTML>
|
|
152
|
+
* <BODY>
|
|
153
|
+
* <DL><p>
|
|
154
|
+
* <DT><A HREF="https://google.com">Google</A>
|
|
155
|
+
* <DT><H3>Development</H3>
|
|
156
|
+
* <DL><p>
|
|
157
|
+
* <DT><A HREF="https://github.com">GitHub</A>
|
|
158
|
+
* </DL><p>
|
|
159
|
+
* </DL>
|
|
160
|
+
* </BODY>
|
|
161
|
+
* </HTML>`;
|
|
162
|
+
*
|
|
163
|
+
* const tree = BookmarksParser.parse(bookmarkHtml);
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
static parse(htmlString: string): BookmarksTree;
|
|
167
|
+
/**
|
|
168
|
+
* Parses a Netscape Bookmark format HTML string and returns a BookmarksTree.
|
|
169
|
+
*
|
|
170
|
+
* @param htmlString HTML string in Netscape Bookmark format
|
|
171
|
+
* @returns The parsed BookmarksTree
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
176
|
+
* <HTML>
|
|
177
|
+
* <BODY>
|
|
178
|
+
* <DL><p>
|
|
179
|
+
* <DT><A HREF="https://google.com">Google</A>
|
|
180
|
+
* <DT><H3>Development</H3>
|
|
181
|
+
* <DL><p>
|
|
182
|
+
* <DT><A HREF="https://github.com">GitHub</A>
|
|
183
|
+
* </DL><p>
|
|
184
|
+
* </DL>
|
|
185
|
+
* </BODY>
|
|
186
|
+
* </HTML>`;
|
|
187
|
+
*
|
|
188
|
+
* const tree = BookmarksParser.parseFromHTMLString(bookmarkHtml);
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
static parseFromHTMLString(htmlString: string): BookmarksTree;
|
|
192
|
+
/**
|
|
193
|
+
* Creates a BookmarksTree from an existing HTMLDocument.
|
|
194
|
+
*
|
|
195
|
+
* This is an alias for {@link BookmarksTree.fromDOM}.
|
|
196
|
+
*
|
|
197
|
+
* Use this when you already have a parsed HTMLDocument and want to convert it to a BookmarksTree.
|
|
198
|
+
*
|
|
199
|
+
* @param dom An HTMLDocument instance
|
|
200
|
+
* @returns The parsed BookmarksTree
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* const dom = new DOMParser().parseFromString(bookmarkHtml, "text/html");
|
|
205
|
+
* const tree = BookmarksParser.parseFromDOM(dom);
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
static parseFromDOM(dom: HTMLDocument): BookmarksTree;
|
|
209
|
+
/**
|
|
210
|
+
* Parses a JSON string and returns a BookmarksTree.
|
|
211
|
+
*
|
|
212
|
+
* @param jsonString JSON string representing the bookmark structure
|
|
213
|
+
* @returns The parsed BookmarksTree
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* const json = '{"Google":"https://google.com","Development":{"GitHub":"https://github.com"}}';
|
|
218
|
+
* const tree = BookmarksParser.parseFromJSONString(json);
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
static parseFromJSONString(jsonString: string): BookmarksTree;
|
|
222
|
+
/**
|
|
223
|
+
* Parses a JSON object and returns a BookmarksTree.
|
|
224
|
+
*
|
|
225
|
+
* This is an alias for {@link BookmarksTree.fromJSON}.
|
|
226
|
+
*
|
|
227
|
+
* @param jsonObj JSON object representing the bookmark structure
|
|
228
|
+
* @returns The parsed BookmarksTree
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* const obj = { "Google": "https://google.com", "Development": { "GitHub": "https://github.com" } };
|
|
233
|
+
* const tree = BookmarksParser.parseFromJSON(obj);
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
static parseFromJSON(jsonObj: Record<string, unknown>): BookmarksTree;
|
|
237
|
+
}
|
|
238
|
+
//#endregion
|
|
239
|
+
//# sourceMappingURL=web.d.ts.map
|