@@ -148,7 +148,7 @@ Third image:
148148 }
149149
150150 Context " Filtering and validation" {
151- It " Should skip HTTP URLs " {
151+ It " Should skip images that are already web hosted (HTTP/HTTPS) " {
152152 $markdownFile = " TestDrive:\with-urls.md"
153153 $markdownContent = @"
154154
@@ -276,4 +276,184 @@ No images here!
276276 $image.LocalPath | Should - BeLike " *test-image1.png"
277277 }
278278 }
279+
280+ Context " Obsidian image format support" {
281+
282+ BeforeAll {
283+ $obsidianTestCases = @ (
284+ @ {
285+ Name = " Basic Obsidian format without alt text"
286+ Content = " ![[test-image1.png]]"
287+ ExpectedCount = 1
288+ ExpectedAltText = " "
289+ ExpectedFileName = " test-image1.png"
290+ ExpectedOriginal = " ![[test-image1.png]]"
291+ },
292+ @ {
293+ Name = " Obsidian format with alt text"
294+ Content = " ![[test-image1.png|My Alt Text]]"
295+ ExpectedCount = 1
296+ ExpectedAltText = " My Alt Text"
297+ ExpectedFileName = " test-image1.png"
298+ ExpectedOriginal = " ![[test-image1.png|My Alt Text]]"
299+ },
300+ @ {
301+ Name = " Obsidian format with subfolder path"
302+ Content = " ![[subfolder/test-image2.jpg|Image in subfolder]]"
303+ ExpectedCount = 1
304+ ExpectedAltText = " Image in subfolder"
305+ ExpectedFileName = " test-image2.jpg"
306+ ExpectedOriginal = " ![[subfolder/test-image2.jpg|Image in subfolder]]"
307+ },
308+ @ {
309+ Name = " Obsidian format with empty alt text after pipe"
310+ Content = " ![[test-image1.png|]]"
311+ ExpectedCount = 1
312+ ExpectedAltText = " "
313+ ExpectedFileName = " test-image1.png"
314+ ExpectedOriginal = " ![[test-image1.png|]]"
315+ },
316+ @ {
317+ Name = " Multiple Obsidian images"
318+ Content = @"
319+ ![[test-image1.png|First image]]
320+ Some text here
321+ ![[subfolder/test-image2.jpg]]
322+ More text
323+ ![[test-image1.png|Duplicate image]]
324+ "@
325+ ExpectedCount = 3
326+ ExpectedAltText = @ (" First image" , " " , " Duplicate image" )
327+ ExpectedFileName = @ (" test-image1.png" , " test-image2.jpg" , " test-image1.png" )
328+ }
329+ )
330+ }
331+
332+ It " Should handle <Name>" - TestCases $obsidianTestCases {
333+ param ($Name , $Content , $ExpectedCount , $ExpectedAltText , $ExpectedFileName , $ExpectedOriginal )
334+
335+ $markdownFile = " TestDrive:\obsidian-test.md"
336+ Set-MarkdownFile $markdownFile $Content
337+
338+ $result = Find-MarkdownImages - File $markdownFile
339+
340+ $result.Count | Should - Be $ExpectedCount
341+
342+ if ($ExpectedCount -eq 1 ) {
343+ $result [0 ].AltText | Should - Be $ExpectedAltText
344+ $result [0 ].FileName | Should - Be $ExpectedFileName
345+ $result [0 ].Title | Should - Be " " # Obsidian format doesn't support titles
346+ if ($ExpectedOriginal ) {
347+ $result [0 ].OriginalMarkdown | Should - Be $ExpectedOriginal
348+ }
349+ } elseif ($ExpectedCount -gt 1 ) {
350+ for ($i = 0 ; $i -lt $ExpectedCount ; $i ++ ) {
351+ $result [$i ].AltText | Should - Be $ExpectedAltText [$i ]
352+ $result [$i ].Format | Should - Be $ExpectedFormat [$i ]
353+ $result [$i ].FileName | Should - Be $ExpectedFileName [$i ]
354+ $result [$i ].Title | Should - Be " "
355+ }
356+ }
357+ }
358+
359+ It " Should skip Obsidian images with HTTP URLs" {
360+ $markdownFile = " TestDrive:\obsidian-urls.md"
361+ $markdownContent = @"
362+ ![[test-image1.png|Local image]]
363+ ![[http://example.com/image.jpg|HTTP image]]
364+ ![[https://example.com/image.png|HTTPS image]]
365+ "@
366+ Set-MarkdownFile $markdownFile $markdownContent
367+
368+ $result = Find-MarkdownImages - File $markdownFile
369+
370+ $result.Count | Should - Be 1
371+ $result [0 ].FileName | Should - Be " test-image1.png"
372+ }
373+
374+ It " Should skip non-existent Obsidian images" {
375+ $markdownFile = " TestDrive:\obsidian-missing.md"
376+ $markdownContent = @"
377+ ![[test-image1.png|Existing image]]
378+ ![[does-not-exist.jpg|Missing image]]
379+ ![[subfolder/test-image2.jpg|Another existing]]
380+ "@
381+ Set-MarkdownFile $markdownFile $markdownContent
382+
383+ $result = Find-MarkdownImages - File $markdownFile
384+
385+ $result.Count | Should - Be 2
386+ $result [0 ].FileName | Should - Be " test-image1.png"
387+ $result [1 ].FileName | Should - Be " test-image2.jpg"
388+ }
389+
390+ It " Should not find embedded markdown content" {
391+ # arrange
392+ # obsidian can link content from an external file as an embedded markdown block
393+ $markdownFile = " TestDrive:\obsidian-embedded.md"
394+ $markdownContent = " ![[Embedded Markdown Page|Title]]"
395+ Set-MarkdownFile $markdownFile $markdownContent
396+
397+ # act
398+ $result = Find-MarkdownImages - File $markdownFile
399+
400+ # assert
401+ $result.Count | Should - Be 0
402+ }
403+ }
404+
405+ Context " Mixed format support (Standard + Obsidian)" {
406+ BeforeAll {
407+ $mixedFormatTestCases = @ (
408+ @ {
409+ Name = " Both standard and Obsidian in same file"
410+ Content = @"
411+ 
412+ ![[test-image1.png|Obsidian image]]
413+ 
414+ ![[subfolder/test-image2.jpg]]
415+ "@
416+ ExpectedCount = 4
417+ ExpectedAltTexts = @ (" Standard image" , " Obsidian image" , " Another standard" , " " )
418+ ExpectedTitles = @ (" Standard title" , " " , " " , " " )
419+ },
420+ @ {
421+ Name = " Standard format only"
422+ Content = @"
423+ 
424+ 
425+ "@
426+ ExpectedCount = 2
427+ ExpectedAltTexts = @ (" Image 1" , " Image 2" )
428+ ExpectedTitles = @ (" " , " With title" )
429+ },
430+ @ {
431+ Name = " Obsidian format only"
432+ Content = @"
433+ ![[test-image1.png|Alt 1]]
434+ ![[subfolder/test-image2.jpg]]
435+ "@
436+ ExpectedCount = 2
437+ ExpectedAltTexts = @ (" Alt 1" , " " )
438+ ExpectedTitles = @ (" " , " " )
439+ }
440+ )
441+ }
442+
443+ It " Should handle <Name>" - TestCases $mixedFormatTestCases {
444+ param ($Name , $Content , $ExpectedCount , $ExpectedAltTexts , $ExpectedTitles )
445+
446+ $markdownFile = " TestDrive:\mixed-format-test.md"
447+ Set-MarkdownFile $markdownFile $Content
448+
449+ $result = Find-MarkdownImages - File $markdownFile
450+
451+ $result.Count | Should - Be $ExpectedCount
452+
453+ for ($i = 0 ; $i -lt $ExpectedCount ; $i ++ ) {
454+ $result [$i ].AltText | Should - Be $ExpectedAltTexts [$i ]
455+ $result [$i ].Title | Should - Be $ExpectedTitles [$i ]
456+ }
457+ }
458+ }
279459}
0 commit comments