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
41 changes: 41 additions & 0 deletions ConvertOneNote2MarkDown-v2.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'] = ''
Expand Down Expand Up @@ -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

Expand Down
26 changes: 20 additions & 6 deletions ConvertOneNote2MarkDown-v2.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
5 changes: 5 additions & 0 deletions config.example.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down