Skip to content

Instantly share code, notes, and snippets.

@heardk
Last active March 27, 2024 03:02
Show Gist options
  • Star 91 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • Save heardk/ded40b72056cee33abb18f3724e0a580 to your computer and use it in GitHub Desktop.
Save heardk/ded40b72056cee33abb18f3724e0a580 to your computer and use it in GitHub Desktop.
Convert notes from OneNote into Markdown

Converting One Note to Markdown

This is an example of how to convert notes from OneNote into Markdown to use in other, less annoying Note applications. I am using PowerShell on Windows here, but other shell/scripting environments would work as well. If you want separate .md files, you'll need to export your OneNote pages separately. Exporting a section, or a selection of pages creates a single .docx file.

  • Download and install Pandoc
  • Export each of your note pages to a .docx (Word) format using OneNote export from the File menu
  • Gather all of these .docx files into a directory
  • Open directory in File Explorer
  • Open Powershell from the File Explorer using File -> Open Windows Powersell
  • Run the following command:

ForEach ($result in Get-ChildItem | select Name, BaseName) { pandoc.exe -f docx -t markdown_strict -i $result.Name -o "$($result.BaseName).md" --wrap=none --atx-headers }

  • markdown-strict is the type of Markdown. Other variants exist in the Pandoc documentation
  • --wrap=none ensures that text in the new .md files doesn't get wrapped to new lines after 80 characters
  • --atx-headers makes headers in the new .md files appear as # h1, ## h2 and so on
@sc420
Copy link

sc420 commented Apr 17, 2023

In pandoc 2.11.2 it has deprecated --atx-headers. Use --markdown-headings=setext|atx instead:

ForEach ($result in Get-ChildItem | select Name, BaseName) { pandoc.exe --from docx --to markdown_strict --output "$($result.BaseName).md" --wrap=none --markdown-headings=atx $result.Name --incremental }

@adzcai
Copy link

adzcai commented Jul 10, 2023

For anyone coming back to this: I indeed tried to get it working with the Graph API, but it seems like the Graph API for onenote is a bit sketchy... not all of my files were showing up there and so I eventually just gave up and started manually copy-pasting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment