1
- import { App , DataAdapter } from " obsidian" ;
2
- import { basename } from " path" ;
3
- import { isValidUrl , normalizeFilename , pathJoin } from "." ;
4
- import { checkAndCreateFolder } from " ./checkAndCreateFolder" ;
5
- import { downloadImage } from " ./downloadImage" ;
6
- import { linkHashes } from " ./linkHash" ;
1
+ import { App , DataAdapter } from ' obsidian' ;
2
+ import { basename } from ' path' ;
3
+ import { isValidUrl , normalizeFilename , pathJoin } from './fileutils' ;
4
+ import { checkAndCreateFolder } from ' ./checkAndCreateFolder' ;
5
+ import { downloadImage } from ' ./downloadImage' ;
6
+ import { linkHashes } from ' ./linkHash' ;
7
7
8
8
export const EXTERNAL_MEDIA_LINK_PATTERN = / \! \[ (?< anchor > .* ?) \] \( (?< link > .+ ?) \) / g;
9
9
export async function replaceImages ( app : App , content : string , assetsDir : string ) {
10
- return await replaceAsync (
11
- content ,
12
- EXTERNAL_MEDIA_LINK_PATTERN ,
13
- imageTagProcessor ( app , assetsDir ) ,
14
- ) ;
10
+ return await replaceAsync ( content , EXTERNAL_MEDIA_LINK_PATTERN , imageTagProcessor ( app , assetsDir ) ) ;
15
11
}
16
12
17
13
export function replaceAsync ( string : string , searchValue : string | RegExp , replacer : any ) {
@@ -58,7 +54,7 @@ export function imageTagProcessor(app: App, mediaDir: string) {
58
54
anchor ,
59
55
link ,
60
56
fileContent ,
61
- fileExtension
57
+ fileExtension ,
62
58
) ;
63
59
64
60
if ( needWrite && fileName ) {
@@ -87,7 +83,6 @@ export function imageTagProcessor(app: App, mediaDir: string) {
87
83
} ;
88
84
}
89
85
90
-
91
86
export const FORBIDDEN_SYMBOLS_FILENAME_PATTERN = / \s + / g;
92
87
93
88
export const FILENAME_TEMPLATE = 'media' ;
@@ -99,7 +94,7 @@ async function chooseFileName(
99
94
baseName : string ,
100
95
link : string ,
101
96
contentData : ArrayBuffer ,
102
- fileExtension : string | false
97
+ fileExtension : string | false ,
103
98
) : Promise < { fileName : string ; needWrite : boolean } > {
104
99
if ( ! fileExtension ) {
105
100
return { fileName : '' , needWrite : false } ;
@@ -152,4 +147,4 @@ async function chooseFileName(
152
147
linkHashes . ensureHashGenerated ( link , contentData ) ;
153
148
154
149
return { fileName, needWrite } ;
155
- }
150
+ }
0 commit comments