diff --git a/ConvertOneNote2MarkDown-v2.Tests.ps1 b/ConvertOneNote2MarkDown-v2.Tests.ps1 index 72d1ae7..f5c323f 100644 --- a/ConvertOneNote2MarkDown-v2.Tests.ps1 +++ b/ConvertOneNote2MarkDown-v2.Tests.ps1 @@ -1792,6 +1792,17 @@ Describe 'Convert-OneNotePage' -Tag 'Unit' { Assert-MockCalled -CommandName Set-ContentNoBom -ParameterFilter { $LiteralPath } -Times 1 -Scope It } + It "Markdown mutation: Removes trailing blank lines" { + Mock Get-Content -ParameterFilter { $LiteralPath -and ! $Raw } { + # 6 lines of header, followed by the content with a newline for each renamed image + @( 1..6 | ForEach-Object { 'some header' } ) + @( 'some text', '', '', '' ) + } + + Convert-OneNotePage @params 6>$null + + Assert-MockCalled -CommandName Set-ContentNoBom -ParameterFilter { $LiteralPath -and $Value -match 'some text\z' } -Times 1 -Scope It + } + It "Does a dry run" { Mock New-Item { 'foo' } Mock Remove-Item { 'foo' } diff --git a/ConvertOneNote2MarkDown-v2.ps1 b/ConvertOneNote2MarkDown-v2.ps1 index 3668cba..9709897 100644 --- a/ConvertOneNote2MarkDown-v2.ps1 +++ b/ConvertOneNote2MarkDown-v2.ps1 @@ -1282,6 +1282,8 @@ Function Convert-OneNotePage { '' } ) -join "`n" + # Remove trailing blank lines. Each write of the markdown file (e.g. when renaming image references, once for each image) appends a newline. A single newline is appended again when writing the final file + $content = $content -replace '[\r\n \t]+\z', '' } # Mutate