Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ConvertOneNote2MarkDown-v2.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down
2 changes: 2 additions & 0 deletions ConvertOneNote2MarkDown-v2.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down