@@ -15,6 +15,49 @@ Describe "Find-MarkdownImages" {
1515 }
1616
1717 Context " Basic image detection" {
18+ It " Should include external images by default" {
19+ # arrange
20+ $markdownFile = " TestDrive:\external.md"
21+ $markdownContent = @ (
22+ " # Test Post"
23+ " "
24+ " External image:"
25+ " "
26+ ) -join [Environment ]::NewLine
27+ Set-MarkdownFile $markdownFile $markdownContent
28+
29+ # act
30+ $result = Find-MarkdownImages - File $markdownFile
31+
32+ # assert
33+ $result.Count | Should - Be 1
34+ $result [0 ].AltText | Should - Be " External"
35+ $result [0 ].RelativePath | Should - Be " https://example.com/image.png"
36+ $result [0 ].LocalPath | Should - Be " https://example.com/image.png"
37+ }
38+
39+ It " Should exclude external images when -ExcludeExternal is used" {
40+ # arrange
41+ $markdownFile = " TestDrive:\external-exclude.md"
42+ $markdownContent = @ (
43+ " # Test Post"
44+ " "
45+ " External image:"
46+ " "
47+ " Local image:"
48+ " "
49+ ) -join [Environment ]::NewLine
50+ Set-MarkdownFile $markdownFile $markdownContent
51+
52+ # act
53+ $result = Find-MarkdownImages - File $markdownFile - ExcludeExternal
54+
55+ # assert
56+ $result.Count | Should - Be 1
57+ $result [0 ].AltText | Should - Be " Local"
58+ $result [0 ].FileName | Should - Be " test-image1.png"
59+ $result [0 ].RelativePath | Should - Be " test-image1.png"
60+ }
1861
1962 It " Should return an empty array if there are no images" {
2063 # arrange
@@ -105,6 +148,12 @@ Describe "Find-MarkdownImages" {
105148 }
106149
107150 Context " Image Path resolution" {
151+ It " Should return the original value for external URLs in Resolve-ImageFilePath" {
152+ InModuleScope PSBlogger {
153+ $result = Resolve-ImageFilePath - FilePath " https://example.com/image.png" - BaseDirectory " TestDrive:/" - AttachmentsDirectory " TestDrive:/attachments"
154+ $result | Should - Be " https://example.com/image.png"
155+ }
156+ }
108157 It " Should resolve relative paths correctly" {
109158 # arrange
110159 $markdownFile = " TestDrive:\relative.md"
@@ -174,7 +223,7 @@ Describe "Find-MarkdownImages" {
174223
175224 It " Should resolve absolute image in the attachments directory" {
176225 # arrange
177- $markdownFile = " TestDrive:\ attachments.md"
226+ $markdownFile = Join-Path " TestDrive" " attachments.md"
178227 $markdownContent = @ (
179228 " "
180229 " "
@@ -187,12 +236,12 @@ Describe "Find-MarkdownImages" {
187236 # assert
188237 $result.Count | Should - Be 1
189238 $result [0 ].FileName | Should - Be " test-attachment1.png"
190- $result [0 ].LocalPath | Should - BeLike " *attachments\ test-attachment1.png"
239+ $result [0 ].LocalPath | Should - BeLike " *attachments* test-attachment1.png"
191240 }
192241
193242 It " Should resolve absolute image with subfolder relative to the attachments directory" {
194243 # arrange
195- $markdownFile = " TestDrive:\ attachments-subfolder.md"
244+ $markdownFile = Join-Path " TestDrive" " attachments-subfolder.md"
196245 $markdownContent = @ (
197246 " "
198247 " "
@@ -205,12 +254,12 @@ Describe "Find-MarkdownImages" {
205254 # assert
206255 $result.Count | Should - Be 1
207256 $result [0 ].FileName | Should - Be " test-attachment2.jpg"
208- $result [0 ].LocalPath | Should - BeLike " *attachments\ subfolder\ test-attachment2.jpg"
257+ $result [0 ].LocalPath | Should - BeLike " *attachments* subfolder* test-attachment2.jpg"
209258 }
210259
211260 It " Should find images in subfolders of the attachments directory when markdown does not specify a subfolder" {
212261 # arrange
213- $markdownFile = " TestDrive:\ attachments-subfolder.md"
262+ $markdownFile = Join-Path " TestDrive" " attachments-subfolder.md"
214263 $markdownContent = @ (
215264 " "
216265 " " # this is in the subfolder
@@ -223,7 +272,7 @@ Describe "Find-MarkdownImages" {
223272 # assert
224273 $result.Count | Should - Be 1
225274 $result [0 ].FileName | Should - Be " test-attachment2.jpg"
226- $result [0 ].LocalPath | Should - BeLike " *attachments\ subfolder\ test-attachment2.jpg"
275+ $result [0 ].LocalPath | Should - BeLike " *attachments* subfolder* test-attachment2.jpg"
227276 }
228277
229278 It " Should use folder of file if attachments directory is not specified" {
@@ -241,7 +290,7 @@ Describe "Find-MarkdownImages" {
241290 # assert
242291 $result.Count | Should - Be 1
243292 $result [0 ].FileName | Should - Be " test-attachment1.png"
244- $result [0 ].LocalPath | Should - BeLike " *attachments\ test-attachment1.png"
293+ $result [0 ].LocalPath | Should - BeLike " *attachments* test-attachment1.png"
245294 }
246295
247296 It " Should use attachments directory user preference if available" {
@@ -265,7 +314,7 @@ Describe "Find-MarkdownImages" {
265314 # assert
266315 $result.Count | Should - Be 1
267316 $result [0 ].FileName | Should - Be " test-attachment1.png"
268- $result [0 ].LocalPath | Should - BeLike " *attachments\ test-attachment1.png"
317+ $result [0 ].LocalPath | Should - BeLike " *attachments* test-attachment1.png"
269318 }
270319 }
271320
@@ -282,7 +331,7 @@ Describe "Find-MarkdownImages" {
282331 Set-MarkdownFile $markdownFile $markdownContent
283332
284333 # act
285- $result = Find-MarkdownImages - File $markdownFile
334+ $result = Find-MarkdownImages - File $markdownFile - ExcludeExternal
286335
287336 # assert
288337 $result.Count | Should - Be 1
@@ -511,7 +560,7 @@ Describe "Find-MarkdownImages" {
511560 Set-MarkdownFile $markdownFile $markdownContent
512561
513562 # act
514- $result = Find-MarkdownImages - File $markdownFile
563+ $result = Find-MarkdownImages - File $markdownFile - ExcludeExternal
515564
516565 # assert
517566 $result.Count | Should - Be 1
0 commit comments