File tree Expand file tree Collapse file tree 3 files changed +87
-2
lines changed Expand file tree Collapse file tree 3 files changed +87
-2
lines changed Original file line number Diff line number Diff line change
1
+ import { Bookmark } from "./Bookmark.js" ;
2
+ import { BuiltinBookmark } from "./BuiltinBookmark.js" ;
3
+
4
+
5
+ class PathFormatter
6
+ {
7
+ encode ( paths )
8
+ {
9
+ return paths . map ( ( path ) => path . replace ( / \/ / g, "\\\/" ) ) . join ( "/" ) ; // replace "/" with "\/" in folder names
10
+ }
11
+
12
+ decode ( url )
13
+ {
14
+ const paths = url . split ( / (?< ! \\ ) \/ / g) ; // split on "/", but not on escaped slashes "\/" in folder names
15
+ return paths . map ( ( path ) => path . replace ( / \\ \/ / g, "/" ) ) ; // replace "\/" with "/"
16
+ }
17
+ }
18
+
19
+
20
+ export class BookmarkFormatterV3
21
+ {
22
+ #builtinBookmark = new BuiltinBookmark ( ) ;
23
+ #version = 3 ;
24
+
25
+ async init ( )
26
+ {
27
+ await this . #builtinBookmark. init ( ) ;
28
+ }
29
+
30
+ read ( rawJson )
31
+ {
32
+ let bookmarks = [ ] ;
33
+ for ( let obj of rawJson )
34
+ {
35
+ let fmt = new PathFormatter ( ) ;
36
+ let path = fmt . decode ( obj [ "path" ] ) ;
37
+ this . #expandRootNodeIn( path ) ;
38
+ bookmarks . push ( new Bookmark (
39
+ obj [ "title" ] ,
40
+ obj [ "url" ] ,
41
+ path ) ) ;
42
+ }
43
+ return bookmarks ;
44
+ }
45
+
46
+ write ( bookmarks )
47
+ {
48
+ let rawJson = [ ] ;
49
+ for ( let bookmark of bookmarks )
50
+ {
51
+ this . #substituteRootNodeIn( bookmark . path ) ;
52
+ let fmt = new PathFormatter ( ) ;
53
+ rawJson . push ( {
54
+ title : bookmark . title ,
55
+ url : bookmark . url ,
56
+ path : fmt . encode ( bookmark . path )
57
+ } ) ;
58
+ }
59
+ return rawJson ;
60
+ }
61
+
62
+ getVersion ( )
63
+ {
64
+ return this . #version;
65
+ }
66
+
67
+ #expandRootNodeIn( path )
68
+ {
69
+ path [ 1 ] = this . #builtinBookmark. expand ( path [ 1 ] ) ;
70
+ }
71
+
72
+ #substituteRootNodeIn( path )
73
+ {
74
+ path [ 1 ] = this . #builtinBookmark. substitute ( path [ 1 ] ) ;
75
+ }
76
+ }
Original file line number Diff line number Diff line change 1
1
import { BookmarkExporter } from "./BookmarkExporter.js" ;
2
2
import { BookmarkTreeExport } from "./BookmarkTreeExport.js" ;
3
3
import { BookmarkFile } from "./BookmarkFile.js" ;
4
- import { BookmarkFormatterV2 } from "./BookmarkFormatterV2 .js" ;
4
+ import { BookmarkFormatterV3 } from "./BookmarkFormatterV3 .js" ;
5
5
6
6
export class TabViewExport
7
7
{
@@ -46,7 +46,7 @@ export class TabViewExport
46
46
const exporter = new BookmarkExporter ( ) ;
47
47
exporter . setBookmarkTree ( this . #bookmarkTree)
48
48
exporter . setSelection ( this . #tree. getSelectedBookmarksId ( ) ) ;
49
- let formatter = new BookmarkFormatterV2 ( ) ;
49
+ let formatter = new BookmarkFormatterV3 ( ) ;
50
50
await formatter . init ( ) ;
51
51
let bookmarks = formatter . write ( exporter . export ( ) ) ;
52
52
let fileWriter = new BookmarkFile ( ) ;
Original file line number Diff line number Diff line change 1
1
import { BookmarkFile } from "./BookmarkFile.js" ;
2
2
import { BookmarkFormatterV1 } from "./BookmarkFormatterV1.js" ;
3
3
import { BookmarkFormatterV2 } from "./BookmarkFormatterV2.js" ;
4
+ import { BookmarkFormatterV3 } from "./BookmarkFormatterV3.js" ;
4
5
import { BookmarkImporter } from "./BookmarkImporter.js" ;
5
6
import { BookmarkTreeImport } from "./BookmarkTreeImport.js" ;
6
7
@@ -75,6 +76,7 @@ export class TabViewImport
75
76
const formatter = {
76
77
"1" : new BookmarkFormatterV1 ( ) ,
77
78
"2" : await this . #newBookmarkFormatterV2( ) ,
79
+ "3" : await this . #newBookmarkFormatterV3( ) ,
78
80
} ;
79
81
if ( version in formatter )
80
82
{
@@ -94,6 +96,13 @@ export class TabViewImport
94
96
return formatter ;
95
97
}
96
98
99
+ async #newBookmarkFormatterV3( )
100
+ {
101
+ const formatter = new BookmarkFormatterV3 ( ) ;
102
+ await formatter . init ( ) ;
103
+ return formatter ;
104
+ }
105
+
97
106
#showImportedStatus( newBookmarks , existingBookmarks )
98
107
{
99
108
const type = "success" ;
You can’t perform that action at this time.
0 commit comments