Skip to content

Commit 07c9175

Browse files
Merge pull request #161 from theohbrothers/enhancement/config-add-ability-for-keepspaces-option-to-strip-extra-newline-between-ordered-list-items
Enhancement (config): Add ability for `$keepspaces` option to strip extra newline between ordered list items
2 parents 015c065 + bf35a3d commit 07c9175

File tree

4 files changed

+56
-28
lines changed

4 files changed

+56
-28
lines changed

ConvertOneNote2MarkDown-v2.Tests.ps1

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,7 @@ Describe 'New-SectionGroupConversionConfig' -Tag 'Unit' {
11901190

11911191
$fakeMarkdownContent = @"
11921192
hello world$( [char]0x00A0 )
1193+
11931194
- foo
11941195
11951196
- foo1
@@ -1198,9 +1199,29 @@ hello world$( [char]0x00A0 )
11981199
11991200
- bar1
12001201
1202+
- baz
1203+
1204+
- baz1
1205+
12011206
>
12021207
>
12031208
> some other text
1209+
1210+
1. foo
1211+
1212+
1. foo1
1213+
1214+
2. bar
1215+
1216+
1. bar1
1217+
1218+
3. baz
1219+
1220+
1. baz1
1221+
1222+
some new paragraph
1223+
some more
1224+
12041225
"@ -replace "`r", '' # On some Windows Powershell 5 versions, a here-string will contain `\r`, so let's ensure that doesn't happen.
12051226

12061227
foreach ($pageCfg in $result) {
@@ -1212,19 +1233,33 @@ hello world$( [char]0x00A0 )
12121233
}
12131234
}
12141235

1215-
# Should remove newlines between bullets, and remove non-breaking spaces. Ignore first 8 lines for page header
1236+
# Should remove extra newline between unordered and ordered lists, remove non-breaking spaces, and '>' from ordered lists. Ignore first 8 lines for page header
12161237
$split = $mutated -split "`n"
12171238
$expectedBody = $split[8..($split.Count - 1)] -join "`n"
12181239
$expectedBody | Should -Be $( @"
12191240
hello world
1241+
12201242
- foo
12211243
- foo1
12221244
- bar
12231245
- bar1
1246+
- baz
1247+
- baz1
12241248
12251249
12261250
12271251
some other text
1252+
1253+
1. foo
1254+
1. foo1
1255+
2. bar
1256+
1. bar1
1257+
3. baz
1258+
1. baz1
1259+
1260+
some new paragraph
1261+
some more
1262+
12281263
"@ -replace "`r", '') # On some Windows Powershell 5 versions, a here-string will contain `\r`, so let's ensure that doesn't happen.
12291264
}
12301265

@@ -1244,23 +1279,10 @@ some other text
12441279
}
12451280
}
12461281

1247-
# Should keep newlines between bullets, and keep non-breaking spaces. Ignore first 8 lines for page header
1282+
# Should keep extra newline between ordered and unordered list items, keep non-breaking spaces, and `>` from ordered lists. Ignore first 8 lines for page header
12481283
$split = $mutated -split "`n"
12491284
$expectedBody = $split[8..($split.Count - 1)] -join "`n"
1250-
$expectedBody | Should -Be $( @"
1251-
hello world$( [char]0x00A0 )
1252-
- foo
1253-
1254-
- foo1
1255-
1256-
- bar
1257-
1258-
- bar1
1259-
1260-
>
1261-
>
1262-
> some other text
1263-
"@ -replace "`r", '') # On some Windows Powershell 5 versions, a here-string will contain `\r`, so let's ensure that doesn't happen.
1285+
$expectedBody | Should -Be $fakeMarkdownContent # On some Windows Powershell 5 versions, a here-string will contain `\r`, so let's ensure that doesn't happen.
12641286
}
12651287

12661288
}

ConvertOneNote2MarkDown-v2.ps1

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ Whether to include page timestamp and separator at top of document
152152
}
153153
keepspaces = @{
154154
description = @'
155-
Whether to clear double spaces between bullets, non-breaking spaces from blank lines, and '>` after bullet lists
156-
1: Clear double spaces in bullets - Default
157-
2: Keep double spaces
155+
Whether to clear extra newlines between unordered (bullet) and ordered (numbered) list items, non-breaking spaces from blank lines, and `>` after unordered lists
156+
1: Clear - Default
157+
2: Don't clear
158158
'@
159159
default = 1
160160
value = 1
@@ -928,18 +928,24 @@ Function New-SectionGroupConversionConfig {
928928
}
929929
if ($config['keepspaces']['value'] -eq 1 ) {
930930
@{
931-
description = 'Clear double spaces from bullets and non-breaking spaces spaces from blank lines'
931+
description = 'Clear extra newlines between unordered (bullet) and ordered (numbered) list items, non-breaking spaces from blank lines, and `>` after unordered lists'
932932
replacements = @(
933+
# Remove non-breaking spaces
933934
@{
934935
searchRegex = [regex]::Escape([char]0x00A0)
935936
replacement = ''
936937
}
937-
# Remove a newline between each occurrence of '- some list item'
938+
# Remove an extra newline between each occurrence of '- some unordered list item'
938939
@{
939-
searchRegex = '\r*\n\r*\n(\s*)- '
940-
replacement = "`n`$1- "
940+
searchRegex = '(\s*)- ([^\r\n]*)\r*\n\r*\n(?=\s*-)'
941+
replacement = "`$1- `$2`n"
941942
}
942-
# Remove all '>' occurrences immediately following bullet lists
943+
# Remove an extra newline between each occurrence of '1. some ordered list item'
944+
@{
945+
searchRegex = '(\s*)(\d+\.) ([^\r\n]*)\r*\n\r*\n(?=\s*\d+\.)'
946+
replacement = "`$1`$2 `$3`n"
947+
}
948+
# Remove all '>' occurrences immediately following unordered lists
943949
@{
944950
searchRegex = '\n>[ ]*'
945951
replacement = "`n"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The powershell script `ConvertOneNote2MarkDown-v2.ps1` will utilize the OneNote
2929
* `markdown_phpextra` (PHP Markdown Extra)
3030
* `markdown_strict` (original unextended Markdown)
3131
* 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
32-
* Choose whether to remove double spaces between bullet points, non-breaking spaces from blank lines, and `>` after bullet lists, which are created when converting with Pandoc
32+
* 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
3333
* Choose whether to remove `\` escape symbol that are created when converting with Pandoc
3434
* Choose whether to use Line Feed (`LF`) or Carriage Return + Line Feed (`CRLF`) for new lines
3535
* 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.

config.example.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ $conversion = 'markdown-simple_tables-multiline_tables-grid_tables+pipe_tables'
6868
# 2: Don't include
6969
$headerTimestampEnabled = 1
7070

71-
# Whether to clear double spaces between bullets, non-breaking spaces from blank lines, and '>` after bullet lists
72-
# 1: Clear double spaces in bullets - Default
73-
# 2: Keep double spaces
71+
# Whether to clear extra newlines between unordered (bullet) and ordered (numbered) list items, non-breaking spaces from blank lines, and `>` after unordered lists
72+
# 1: Clear - Default
73+
# 2: Don't clear
7474
$keepspaces = 1
7575

7676
# Whether to clear escape symbols from md files. See: https://pandoc.org/MANUAL.html#backslash-escapes

0 commit comments

Comments
 (0)