netscape-bookmark-parser 1.1.2 → 1.1.3
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 +16 -20
- package/README.md +17 -22
- package/esm/src/BookmarksParser/BookmarksParser.d.ts +55 -0
- package/esm/src/BookmarksParser/BookmarksParser.d.ts.map +1 -1
- package/esm/src/BookmarksParser/BookmarksParser.js +55 -0
- package/esm/src/BookmarksTree/BookmarksTree.d.ts +96 -0
- package/esm/src/BookmarksTree/BookmarksTree.d.ts.map +1 -1
- package/esm/src/BookmarksTree/BookmarksTree.js +96 -0
- package/esm/src/web/BookmarksParser/BookmarksParser.d.ts +55 -0
- package/esm/src/web/BookmarksParser/BookmarksParser.d.ts.map +1 -1
- package/esm/src/web/BookmarksParser/BookmarksParser.js +55 -0
- package/esm/src/web/BookmarksTree/BookmarksTree.d.ts +96 -0
- package/esm/src/web/BookmarksTree/BookmarksTree.d.ts.map +1 -1
- package/esm/src/web/BookmarksTree/BookmarksTree.js +96 -0
- package/package.json +1 -1
package/README-ja.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Netscape Bookmark Parser
|
|
2
2
|
|
|
3
|
+
ブラウザのブックマークファイル(HTML 形式)を解析し、構造化データとして操作するための TypeScript/JavaScript ライブラリです。Deno と Node.js の両方のランタイムに対応しています。
|
|
4
|
+
|
|
3
5
|
> **注意:**
|
|
4
6
|
> この README は AI 生成されたドキュメントです。詳細はほぼ正確ですが、不正確な説明が含まれる可能性があります。
|
|
5
7
|
|
|
6
|
-
ブラウザのブックマークファイル(HTML 形式)を解析し、構造化データとして操作するための TypeScript/JavaScript ライブラリです。Deno と Node.js の両方のランタイムに対応しています。
|
|
7
|
-
|
|
8
8
|
## 機能
|
|
9
9
|
|
|
10
10
|
- **HTML ブックマークファイルの解析**: Chrome、Firefox、Safari、その他のブラウザからエクスポートされた HTML ブックマークファイルを解析
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
npm install netscape-bookmark-parser
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
```typescript
|
|
26
|
+
import { BookmarksParser, BookmarksTree } from "netscape-bookmark-parser";
|
|
27
|
+
```
|
|
28
|
+
|
|
25
29
|
### Deno
|
|
26
30
|
|
|
27
31
|
```typescript
|
|
@@ -58,26 +62,13 @@ function handleFileUpload(event: Event) {
|
|
|
58
62
|
}
|
|
59
63
|
```
|
|
60
64
|
|
|
61
|
-
#### オプション 2:
|
|
62
|
-
|
|
63
|
-
```html
|
|
64
|
-
<script type="module">
|
|
65
|
-
import {
|
|
66
|
-
BookmarksParser,
|
|
67
|
-
BookmarksTree,
|
|
68
|
-
} from "./node_modules/netscape-bookmark-parser/esm/mod_web.js";
|
|
69
|
-
|
|
70
|
-
// ブックマーク処理コードをここに...
|
|
71
|
-
</script>
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
#### オプション 3: Import Maps を使用した CDN
|
|
65
|
+
#### オプション 2: Import Maps を使用した CDN
|
|
75
66
|
|
|
76
67
|
```html
|
|
77
68
|
<script type="importmap">
|
|
78
69
|
{
|
|
79
70
|
"imports": {
|
|
80
|
-
"netscape-bookmark-parser/web": "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.
|
|
71
|
+
"netscape-bookmark-parser/web": "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.3/esm/mod_web.js"
|
|
81
72
|
}
|
|
82
73
|
}
|
|
83
74
|
</script>
|
|
@@ -89,14 +80,14 @@ function handleFileUpload(event: Event) {
|
|
|
89
80
|
</script>
|
|
90
81
|
```
|
|
91
82
|
|
|
92
|
-
#### オプション
|
|
83
|
+
#### オプション 3: CDN を直接インポート
|
|
93
84
|
|
|
94
85
|
```html
|
|
95
86
|
<script type="module">
|
|
96
87
|
import {
|
|
97
88
|
BookmarksParser,
|
|
98
89
|
BookmarksTree,
|
|
99
|
-
} from "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.
|
|
90
|
+
} from "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.3/esm/mod_web.js";
|
|
100
91
|
|
|
101
92
|
// import maps なしでの直接 CDN インポート
|
|
102
93
|
</script>
|
|
@@ -622,7 +613,12 @@ MIT License - 詳細は[LICENSE](LICENSE)ファイルを参照してください
|
|
|
622
613
|
|
|
623
614
|
## 変更履歴
|
|
624
615
|
|
|
625
|
-
### v1.1.
|
|
616
|
+
### v1.1.3(最新)
|
|
617
|
+
|
|
618
|
+
- 📝 **JSDoc コメント追加**: 主要なクラス・メソッドに JSDoc 形式のコメントを追加し、型情報と API 自動ドキュメント生成を強化
|
|
619
|
+
- 📚 **ドキュメント更新**: インストール手順(Node.js/npm)に TypeScript でのインポート例を追加
|
|
620
|
+
|
|
621
|
+
### v1.1.2
|
|
626
622
|
|
|
627
623
|
- 📝 **ドキュメント強化**: 最新バージョン参照と改善された例を含む包括的な README ドキュメントの更新
|
|
628
624
|
- 🔧 **バージョン一貫性**: 全ドキュメントとコード例でのバージョン番号の同期
|
package/README.md
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
# Netscape Bookmark Parser
|
|
2
2
|
|
|
3
|
-
> **Note:**
|
|
4
|
-
> This README is an AI-generated document. Details are mostly accurate but might include inaccurate description.
|
|
5
|
-
|
|
6
3
|
A TypeScript/JavaScript library for parsing browser bookmark files (HTML format) and manipulating them as structured data. Compatible with both Deno and Node.js runtimes.
|
|
7
4
|
|
|
8
|
-
|
|
5
|
+
> **Note:**
|
|
6
|
+
> This README is an AI-generated document. Details are mostly accurate but might include inaccurate description.
|
|
7
|
+
> 日本語ドキュメント: [`./README-ja.md`](./README-ja.md)
|
|
9
8
|
|
|
10
9
|
## Features
|
|
11
10
|
|
|
@@ -24,6 +23,10 @@ A TypeScript/JavaScript library for parsing browser bookmark files (HTML format)
|
|
|
24
23
|
npm install netscape-bookmark-parser
|
|
25
24
|
```
|
|
26
25
|
|
|
26
|
+
```typescript
|
|
27
|
+
import { BookmarksParser, BookmarksTree } from "netscape-bookmark-parser";
|
|
28
|
+
```
|
|
29
|
+
|
|
27
30
|
### Deno
|
|
28
31
|
|
|
29
32
|
```typescript
|
|
@@ -60,26 +63,13 @@ function handleFileUpload(event: Event) {
|
|
|
60
63
|
}
|
|
61
64
|
```
|
|
62
65
|
|
|
63
|
-
#### Option 2:
|
|
64
|
-
|
|
65
|
-
```html
|
|
66
|
-
<script type="module">
|
|
67
|
-
import {
|
|
68
|
-
BookmarksParser,
|
|
69
|
-
BookmarksTree,
|
|
70
|
-
} from "./node_modules/netscape-bookmark-parser/esm/mod_web.js";
|
|
71
|
-
|
|
72
|
-
// Your bookmark processing code here...
|
|
73
|
-
</script>
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
#### Option 3: CDN with Import Maps
|
|
66
|
+
#### Option 2: CDN with Import Maps
|
|
77
67
|
|
|
78
68
|
```html
|
|
79
69
|
<script type="importmap">
|
|
80
70
|
{
|
|
81
71
|
"imports": {
|
|
82
|
-
"netscape-bookmark-parser/web": "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.
|
|
72
|
+
"netscape-bookmark-parser/web": "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.3/esm/mod_web.js"
|
|
83
73
|
}
|
|
84
74
|
}
|
|
85
75
|
</script>
|
|
@@ -91,14 +81,14 @@ function handleFileUpload(event: Event) {
|
|
|
91
81
|
</script>
|
|
92
82
|
```
|
|
93
83
|
|
|
94
|
-
#### Option
|
|
84
|
+
#### Option 3: Direct CDN Import
|
|
95
85
|
|
|
96
86
|
```html
|
|
97
87
|
<script type="module">
|
|
98
88
|
import {
|
|
99
89
|
BookmarksParser,
|
|
100
90
|
BookmarksTree,
|
|
101
|
-
} from "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.
|
|
91
|
+
} from "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.3/esm/mod_web.js";
|
|
102
92
|
|
|
103
93
|
// Direct CDN import without import maps
|
|
104
94
|
</script>
|
|
@@ -623,7 +613,12 @@ When reporting issues, please include:
|
|
|
623
613
|
|
|
624
614
|
## Changelog
|
|
625
615
|
|
|
626
|
-
### v1.1.
|
|
616
|
+
### v1.1.3 (Latest)
|
|
617
|
+
|
|
618
|
+
- 📝 **Added JSDoc comments**: Added JSDoc-style comments to major classes and methods to improve type information and enable automatic API documentation generation
|
|
619
|
+
- 📚 **Documentation Update**: Added TypeScript import example for Node.js/npm in the Installation section
|
|
620
|
+
|
|
621
|
+
### v1.1.2
|
|
627
622
|
|
|
628
623
|
- 📝 **Documentation Enhancement**: Updated comprehensive README documentation with latest version references and improved examples
|
|
629
624
|
- 🔧 **Version Consistency**: Synchronized version numbers across all documentation and code examples
|
|
@@ -5,7 +5,62 @@
|
|
|
5
5
|
* https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
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
|
+
*/
|
|
8
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
|
+
*/
|
|
9
64
|
static parse(data: string): BookmarksTree;
|
|
10
65
|
}
|
|
11
66
|
//# sourceMappingURL=BookmarksParser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BookmarksParser.d.ts","sourceRoot":"","sources":["../../../src/src/BookmarksParser/BookmarksParser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,qBAAa,eAAe;IAC3B,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa;CAKzC"}
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa;CAKzC"}
|
|
@@ -6,7 +6,62 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { DOMParser } from "../deps.js";
|
|
8
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
|
+
*/
|
|
9
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
|
+
*/
|
|
10
65
|
static parse(data) {
|
|
11
66
|
const dom = new DOMParser().parseFromString(data, "text/html");
|
|
12
67
|
const tree = BookmarksTree.fromDOM(dom);
|
|
@@ -5,12 +5,108 @@
|
|
|
5
5
|
* https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
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
|
+
*/
|
|
8
24
|
export declare class BookmarksTree extends Map<string, string | BookmarksTree> {
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new BookmarksTree instance
|
|
27
|
+
*/
|
|
9
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
|
+
*/
|
|
10
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
|
+
*/
|
|
11
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
|
+
*/
|
|
12
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
|
+
*/
|
|
13
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
|
+
*/
|
|
14
110
|
get HTMLText(): string;
|
|
15
111
|
}
|
|
16
112
|
//# sourceMappingURL=BookmarksTree.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,qBAAa,aAAc,SAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;;
|
|
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"}
|
|
@@ -5,10 +5,44 @@
|
|
|
5
5
|
* https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
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
|
+
*/
|
|
8
24
|
export class BookmarksTree extends Map {
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new BookmarksTree instance
|
|
27
|
+
*/
|
|
9
28
|
constructor() {
|
|
10
29
|
super();
|
|
11
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
|
+
*/
|
|
12
46
|
toJSON() {
|
|
13
47
|
const json = {};
|
|
14
48
|
for (const [key, value] of this.entries()) {
|
|
@@ -21,6 +55,21 @@ export class BookmarksTree extends Map {
|
|
|
21
55
|
}
|
|
22
56
|
return json;
|
|
23
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
|
+
*/
|
|
24
73
|
static fromJSON(json) {
|
|
25
74
|
const tree = new BookmarksTree();
|
|
26
75
|
if (typeof json === "object" && json !== null) {
|
|
@@ -35,6 +84,23 @@ export class BookmarksTree extends Map {
|
|
|
35
84
|
}
|
|
36
85
|
return tree;
|
|
37
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
|
+
*/
|
|
38
104
|
static fromDOM(dom) {
|
|
39
105
|
const tree = new BookmarksTree();
|
|
40
106
|
const document = dom;
|
|
@@ -76,9 +142,39 @@ export class BookmarksTree extends Map {
|
|
|
76
142
|
}
|
|
77
143
|
return tree;
|
|
78
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
|
+
*/
|
|
79
159
|
toDOM() {
|
|
80
160
|
return new DOMParser().parseFromString(this.HTMLText, "text/html");
|
|
81
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
|
+
*/
|
|
82
178
|
get HTMLText() {
|
|
83
179
|
const escapeHtml = (text) => {
|
|
84
180
|
return text
|
|
@@ -5,7 +5,62 @@
|
|
|
5
5
|
* https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
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
|
+
*/
|
|
8
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
|
+
*/
|
|
9
64
|
static parse(data: string): BookmarksTree;
|
|
10
65
|
}
|
|
11
66
|
//# sourceMappingURL=BookmarksParser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,qBAAa,eAAe;IAC3B,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa;CAKzC"}
|
|
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"}
|
|
@@ -6,7 +6,62 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { DOMParser } from "../deps.js";
|
|
8
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
|
+
*/
|
|
9
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
|
+
*/
|
|
10
65
|
static parse(data) {
|
|
11
66
|
const dom = new DOMParser().parseFromString(data, "text/html");
|
|
12
67
|
const tree = BookmarksTree.fromDOM(dom);
|
|
@@ -5,12 +5,108 @@
|
|
|
5
5
|
* https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
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
|
+
*/
|
|
8
24
|
export declare class BookmarksTree extends Map<string, string | BookmarksTree> {
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new BookmarksTree instance
|
|
27
|
+
*/
|
|
9
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
|
+
*/
|
|
10
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
|
+
*/
|
|
11
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
|
+
*/
|
|
12
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
|
+
*/
|
|
13
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
|
+
*/
|
|
14
110
|
get HTMLText(): string;
|
|
15
111
|
}
|
|
16
112
|
//# sourceMappingURL=BookmarksTree.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,qBAAa,aAAc,SAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;;
|
|
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"}
|
|
@@ -5,10 +5,44 @@
|
|
|
5
5
|
* https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
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
|
+
*/
|
|
8
24
|
export class BookmarksTree extends Map {
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new BookmarksTree instance
|
|
27
|
+
*/
|
|
9
28
|
constructor() {
|
|
10
29
|
super();
|
|
11
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
|
+
*/
|
|
12
46
|
toJSON() {
|
|
13
47
|
const json = {};
|
|
14
48
|
for (const [key, value] of this.entries()) {
|
|
@@ -21,6 +55,21 @@ export class BookmarksTree extends Map {
|
|
|
21
55
|
}
|
|
22
56
|
return json;
|
|
23
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
|
+
*/
|
|
24
73
|
static fromJSON(json) {
|
|
25
74
|
const tree = new BookmarksTree();
|
|
26
75
|
if (typeof json === "object" && json !== null) {
|
|
@@ -35,6 +84,23 @@ export class BookmarksTree extends Map {
|
|
|
35
84
|
}
|
|
36
85
|
return tree;
|
|
37
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
|
+
*/
|
|
38
104
|
static fromDOM(dom) {
|
|
39
105
|
const tree = new BookmarksTree();
|
|
40
106
|
const document = dom;
|
|
@@ -76,9 +142,39 @@ export class BookmarksTree extends Map {
|
|
|
76
142
|
}
|
|
77
143
|
return tree;
|
|
78
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
|
+
*/
|
|
79
159
|
toDOM() {
|
|
80
160
|
return new DOMParser().parseFromString(this.HTMLText, "text/html");
|
|
81
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
|
+
*/
|
|
82
178
|
get HTMLText() {
|
|
83
179
|
const escapeHtml = (text) => {
|
|
84
180
|
return text
|