diff --git a/ConvertOneNote2MarkDown-v2.Tests.ps1 b/ConvertOneNote2MarkDown-v2.Tests.ps1 index 72d1ae7..5cd615e 100644 --- a/ConvertOneNote2MarkDown-v2.Tests.ps1 +++ b/ConvertOneNote2MarkDown-v2.Tests.ps1 @@ -1233,6 +1233,30 @@ hello world$( [char]0x00A0 ) some new paragraph some more +$( [char]0x00A0 ) + +text after an empty paragraph + +$( [char]0x00A0 ) + +$( [char]0x00A0 ) + +text after two empty paragraphs + +- qux + + $( [char]0x00A0 ) + +- quux + +> quote +> +> $( [char]0x00A0 ) +> +> quote after an empty paragraph + +$( [char]0x00A0 ) + "@ -replace "`r", '' # On some Windows Powershell 5 versions, a here-string will contain `\r`, so let's ensure that doesn't happen. foreach ($pageCfg in $result) { @@ -1244,7 +1268,7 @@ some more } } - # Should remove extra newline between unordered and ordered lists, remove non-breaking spaces, and '>' from ordered lists. Ignore first 8 lines for page header + # Should remove extra newline between unordered and ordered lists, remove empty paragraphs, remove non-breaking spaces, and '>' from ordered lists. Ignore first 8 lines for page header $split = $mutated -split "`n" $expectedBody = $split[8..($split.Count - 1)] -join "`n" $expectedBody | Should -Be $( @" @@ -1271,6 +1295,17 @@ some other text some new paragraph some more +text after an empty paragraph + +text after two empty paragraphs + +- qux +- quux + +quote + +quote after an empty paragraph + "@ -replace "`r", '') # On some Windows Powershell 5 versions, a here-string will contain `\r`, so let's ensure that doesn't happen. } diff --git a/ConvertOneNote2MarkDown-v2.ps1 b/ConvertOneNote2MarkDown-v2.ps1 index 3668cba..09ec2ec 100644 --- a/ConvertOneNote2MarkDown-v2.ps1 +++ b/ConvertOneNote2MarkDown-v2.ps1 @@ -152,7 +152,7 @@ Whether to include page timestamp and separator at top of document } keepspaces = @{ description = @' -Whether to clear extra newlines between unordered (bullet) and ordered (numbered) list items, non-breaking spaces from blank lines, and `>` after unordered lists +Whether to clear extra newlines between unordered (bullet) and ordered (numbered) list items, empty paragraphs (blank lines containing only non-breaking spaces), non-breaking spaces, and `>` after unordered lists 1: Clear - Default 2: Don't clear '@ @@ -931,8 +931,13 @@ Function New-SectionGroupConversionConfig { } if ($config['keepspaces']['value'] -eq 1 ) { @{ - description = 'Clear extra newlines between unordered (bullet) and ordered (numbered) list items, non-breaking spaces from blank lines, and `>` after unordered lists' + description = 'Clear extra newlines between unordered (bullet) and ordered (numbered) list items, empty paragraphs (blank lines containing only non-breaking spaces), non-breaking spaces, and `>` after unordered lists' replacements = @( + # Remove empty paragraphs, including the blank line before them. Pandoc converts each empty paragraph to a line containing only a non-breaking space, which would otherwise leave three blank lines between paragraphs + @{ + searchRegex = '\r*\n[ \t>]*\r*\n[ \t>]*\xA0[\xA0 \t]*(?=\r*\n|$)' + replacement = '' + } # Remove non-breaking spaces @{ searchRegex = [regex]::Escape([char]0x00A0) diff --git a/README.md b/README.md index c23006f..cd0862c 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ The powershell script `ConvertOneNote2MarkDown-v2.ps1` will utilize the OneNote * `markdown_phpextra` (PHP Markdown Extra) * `markdown_strict` (original unextended Markdown) * Improved headers, with title now as a `#` heading, standardized `DateTime` format for created and modified dates, and horizontal line to separate from rest of document -* Choose whether to clear extra newlines between unordered (bullet) and ordered (numbered) list items, non-breaking spaces from blank lines, and `>` after unordered lists, which are created when converting with Pandoc +* Choose whether to clear extra newlines between unordered (bullet) and ordered (numbered) list items, empty paragraphs (blank lines containing only non-breaking spaces), non-breaking spaces, and `>` after unordered lists, which are created when converting with Pandoc * Choose whether to remove `\` escape symbol that are created when converting with Pandoc * Choose whether to use Line Feed (`LF`) or Carriage Return + Line Feed (`CRLF`) for new lines * Choose whether to include a `.pdf` export alongside the `.md` file. `.md` does not preserve `InkDrawing` (i.e. overlayed drawings, highlights, pen marks) absolute positions within a page, but a `.pdf` export is a complete page snapshot that preserves `InkDrawing` absolute positions within a page. diff --git a/config.example.ps1 b/config.example.ps1 index 6077bdf..c01dcd2 100644 --- a/config.example.ps1 +++ b/config.example.ps1 @@ -68,7 +68,7 @@ $conversion = 'markdown-simple_tables-multiline_tables-grid_tables+pipe_tables' # 2: Don't include $headerTimestampEnabled = 1 -# Whether to clear extra newlines between unordered (bullet) and ordered (numbered) list items, non-breaking spaces from blank lines, and `>` after unordered lists +# Whether to clear extra newlines between unordered (bullet) and ordered (numbered) list items, empty paragraphs (blank lines containing only non-breaking spaces), non-breaking spaces, and `>` after unordered lists # 1: Clear - Default # 2: Don't clear $keepspaces = 1