diff --git a/ConvertOneNote2MarkDown-v2.Tests.ps1 b/ConvertOneNote2MarkDown-v2.Tests.ps1 index 72d1ae7..0b64993 100644 --- a/ConvertOneNote2MarkDown-v2.Tests.ps1 +++ b/ConvertOneNote2MarkDown-v2.Tests.ps1 @@ -59,6 +59,7 @@ $usedocx = '1' $prefixFolders = 1 $medialocation = 1 $conversion = 'markdown-simple_tables-multiline_tables-grid_tables+pipe_tables' # Default +$headerTitleEnabled = 1 $headerTimestampEnabled = 1 $keepspaces = 1 $keepescape = 1 @@ -86,6 +87,7 @@ $newlineCharacter = 1 $fakeUserInputs['mdFileNameAndFolderNameMaxLength']['value'] = '' $fakeUserInputs['medialocation']['value'] = '' $fakeUserInputs['conversion']['value'] = '' + $fakeUserInputs['headerTitleEnabled']['value'] = '' $fakeUserInputs['headerTimestampEnabled']['value'] = '' $fakeUserInputs['keepspaces']['value'] = '' $fakeUserInputs['keepescape']['value'] = '' @@ -1191,6 +1193,45 @@ Describe 'New-SectionGroupConversionConfig' -Tag 'Unit' { } } + It "Should honor config headerTitleEnabled" { + foreach ($headerTimestampEnabled in 1, 2) { + $params['Config']['headerTitleEnabled']['value'] = 2 + $params['Config']['headerTimestampEnabled']['value'] = $headerTimestampEnabled + + $result = @( New-SectionGroupConversionConfig @params 6>$null ) + + # 15 pages from 'test' notebook, 15 pages from 'test2' notebook + $result.Count | Should -Be 48 + + foreach ($pageCfg in $result) { + $fakeMarkdownContent = '' + + # Mutate + foreach ($m in $pageCfg['mutations']) { + foreach ($r in $m['replacements']) { + $fakeMarkdownContent = $fakeMarkdownContent -replace $r['searchRegex'], $r['replacement'] + } + } + + if ($headerTimestampEnabled -eq 1) { + # Should add only a date, newline, separator + $fakeMarkdownContent = $fakeMarkdownContent -split "`n" + $fakeMarkdownContent.Count | Should -Be 7 + $fakeMarkdownContent[0] | Should -Match '^Created: (.+)$' + $fakeMarkdownContent[1] | Should -Match '^\s*$' + $fakeMarkdownContent[2] | Should -Match '^Modified: (.+)$' + $fakeMarkdownContent[3] | Should -Match '^\s*$' + $fakeMarkdownContent[4] | Should -Be '---' + $fakeMarkdownContent[5] | Should -Match '^\s*$' + $fakeMarkdownContent[6] | Should -Match '^\s*$' + }else { + # Should add nothing + $fakeMarkdownContent | Should -Be '' + } + } + } + } + It "Should honor config keepspaces" { $params['Config']['keepspaces']['value'] = 1 diff --git a/ConvertOneNote2MarkDown-v2.ps1 b/ConvertOneNote2MarkDown-v2.ps1 index 3668cba..755bc6a 100644 --- a/ConvertOneNote2MarkDown-v2.ps1 +++ b/ConvertOneNote2MarkDown-v2.ps1 @@ -140,6 +140,16 @@ Default: default = 'markdown-simple_tables-multiline_tables-grid_tables+pipe_tables' value = 'markdown-simple_tables-multiline_tables-grid_tables+pipe_tables' } + headerTitleEnabled = @{ + description = @' +Whether to include page title as a heading at top of document. Some markdown viewers (e.g. Obsidian) already show the file name as the title +1: Include - Default +2: Don't include +'@ + default = 1 + value = 1 + validateRange = 1,2 + } headerTimestampEnabled = @{ description = @' Whether to include page timestamp and separator at top of document @@ -918,12 +928,16 @@ Function New-SectionGroupConversionConfig { @{ searchRegex = '^\s*' replacement = & { - $heading = "# $( $pageCfg['object'].name )" - if ($config['headerTimestampEnabled']['value'] -eq 1) { - $heading += "`n`nCreated: $( $pageCfg['dateTime'].ToString('yyyy-MM-dd HH:mm:ss zz00') )" - $heading += "`n`nModified: $( $pageCfg['lastModifiedTime'].ToString('yyyy-MM-dd HH:mm:ss zz00') )" - $heading += "`n`n---`n`n" - } + $heading = @( + if ($config['headerTitleEnabled']['value'] -eq 1) { + "# $( $pageCfg['object'].name )" + } + if ($config['headerTimestampEnabled']['value'] -eq 1) { + "Created: $( $pageCfg['dateTime'].ToString('yyyy-MM-dd HH:mm:ss zz00') )" + "Modified: $( $pageCfg['lastModifiedTime'].ToString('yyyy-MM-dd HH:mm:ss zz00') )" + "---`n`n" + } + ) -join "`n`n" $heading } } diff --git a/config.example.ps1 b/config.example.ps1 index 6077bdf..c684d51 100644 --- a/config.example.ps1 +++ b/config.example.ps1 @@ -63,6 +63,11 @@ $medialocation = 1 # markdown-simple_tables-multiline_tables-grid_tables+pipe_tables $conversion = 'markdown-simple_tables-multiline_tables-grid_tables+pipe_tables' +# Whether to include page title as a heading at top of document. Some markdown viewers (e.g. Obsidian) already show the file name as the title +# 1: Include - Default +# 2: Don't include +$headerTitleEnabled = 1 + # Whether to include page timestamp and separator at top of document # 1: Include - Default # 2: Don't include