1414. PARAMETER AttachmentsDirectory
1515 The directory where attachments are stored. If specified, it will be used to resolve relative paths for images.
1616
17+ . PARAMETER ExcludeExternal
18+ If specified, excludes images with external URLs (starting with https). Otherwise, all images are returned.
19+
1720. EXAMPLE
1821 Find-MarkdownImages -File "post.md"
1922
@@ -30,7 +33,10 @@ function Find-MarkdownImages {
3033 [string ]$File ,
3134
3235 [Parameter (Mandatory = $false )]
33- [string ]$AttachmentsDirectory
36+ [string ]$AttachmentsDirectory ,
37+
38+ [Parameter (Mandatory = $false )]
39+ [switch ]$ExcludeExternal
3440 )
3541
3642 $content = Get-Content - Path $File - Raw
@@ -102,8 +108,8 @@ function Find-MarkdownImages {
102108 $title = " " # Obsidian format doesn't support titles
103109 }
104110
105- # Skip URLs (images already hosted online)
106- if ($imagePath -match ' ^https ?://' ) {
111+ # Conditionally skip external URLs if -ExcludeExternal is specified
112+ if ($ExcludeExternal -and ( $ imagePath -match ' ^http(s) ?://' ) ) {
107113 continue
108114 }
109115
@@ -114,7 +120,7 @@ function Find-MarkdownImages {
114120 - AttachmentsDirectory $AttachmentsDirectory
115121
116122 # Check if the file exists
117- if (Test-Path - Path $resolvedPath - PathType Leaf) {
123+ if ($resolvedPath -match ' ^http(s)?:// ' -or ( Test-Path - Path $resolvedPath - PathType Leaf) ) {
118124 $images += New-MarkdownImage `
119125 - OriginalMarkdown $match.Value `
120126 - AltText $altText `
@@ -164,6 +170,10 @@ Function Resolve-ImageFilePath
164170 # If the path is absolute, use it as is
165171 $resolvedPath = $FilePath
166172 }
173+ if ($FilePath -match ' ^http(s)?://' ) {
174+ Write-Verbose " Found external image URL: $FilePath "
175+ return $FilePath
176+ }
167177 if (Test-Path $resolvedPath ) {
168178 Write-Verbose " Found image at base directory: $resolvedPath "
169179 return $resolvedPath
0 commit comments