hi all,
just came across an old onenote notebook and was able to get it converted to markdown and imported to logseq. for better or worse i wanted the pages in a OneNote parent namespace with a sub-namespace per notebook, e.g. OneNote/Notebook 1/Note A. i got a bit hung up getting namespaces to work and came up with this janky workaround if it helps anyone else in the future:
-
Used OneNote Md Exporter from GitHub - alxnbl/onenote-md-exporter: ConsoleApp to export OneNote notebooks to Markdown formats to convert OneNote notebook pages to markdown files.
-
OneNote Md Exporter creates subfolders for each notebook, which could be incorporated into the markdown filenames as namespaces for Logseq Desktop (non-DB version). I used a powershell snippet adapted from https://superuser.com/questions/1571699/adding-folder-names-to-filenames-using-powershell to prepend folder names to the files inside (adding
%2Fto seperate namespace from filename):
cd "\path\to\OneNote_export_folders"
get-childitem -recurse |
Where-Object {$_.Psiscontainer -eq $false} |
Rename-Item -NewName {$_.Directory.Name + "%2F" + $_.Name}
- (a) Move all renamed files to the parent folder using https://stackoverflow.com/questions/38063424/powershell-move-all-files-from-folders-and-subfolders-into-single-folder powershell snippet:
Get-ChildItem -Path "\path\to\OneNote_export_folders" -Recurse -File | Move-Item -Destination "\path\to\OneNote_export_folders"
-
(b) Optional - I then renamed the folder containing all
.mdfiles toOneNoteand ran the snippet again from step 2, adjusted as needed to prependOneNote%2Fto each filename (could probably be incorporated into step 2 but this was just a quick fix after the fact). -
It turns out OneNote Md Exporter adds a header with
title:specified which overrides namespaces in Logseq. I removed thetitle:lines from each file per https://www.reddit.com/r/PowerShell/comments/tydl1p/script_to_remove_lines_from_csv_file_that_contain/:
$fileList = Get-ChildItem "\path\to\OneNote_exported_md_files" -Filter '*.md'
foreach ($file in $fileList) {
$content = Select-String -Path $file -Pattern ^title:.*$ -NotMatch | Select-Object -ExpandProperty Line
Set-Content -Path $file.FullName -Value $content
}
- I then dropped all
.mdfiles into the Logseqpagesfolder and re-indexed. Notes were now namespaced pages!