Skip to content

Instantly share code, notes, and snippets.

@heardk
Last active May 8, 2023 09:15
Embed
What would you like to do?
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
@ichemshirova
Copy link

any clues on how to achieve this on mac OS?

@heardk
Copy link
Author

heardk commented Nov 19, 2019

You can download and install Pandoc on Mac OS: https://pandoc.org/installing.html Then you should just be able to use commands in the terminal to get what you want. See examples on the Pandoc site.

@SjoerdV
Copy link

SjoerdV commented May 30, 2020

Shameless Plug: if you want to do OneNote2Markdown conversion and have better Notebook/Section/Page and image handling, try the script here:
https://github.com/SjoerdV/ConvertOneNote2MarkDown

@projectje
Copy link

Why is -i used ?

@C0rporeus
Copy link

@projectje In my case I need to export my notes from OneNote to use them in a software called "obsidian" this in order to implement "zettelkasten" as a study methodology

@simpleneeraj
Copy link

Helo

joanna-kosinska-vouDD7K0FoA-unsplash

@projectje
Copy link

projectje commented Dec 14, 2021

@C0rporeus

-i, --incremental

Make list items in slide shows display incrementally (one by one). The default is for lists to be displayed all at once.

I wrote / copied and pasted together a little while ago a one-note exporter but when i looked at this one i noticed the -i so back then i thought it was a bug. (did: https://github.com/projectje/OneNoteExporterAkaPublisher/blob/master/Modules/Pandoc/Pandoc.psm1 )

@rrandor1
Copy link

rrandor1 commented Mar 11, 2022

@SjoerdV Does your code work with Mac? What modifications are needed?

@SjoerdV
Copy link

SjoerdV commented Mar 11, 2022

@SjoerdV Does your code work with Mac? What modifications are needed?

afraid not. The API used in the script is Windows only (COM objects and stuff..). Rewrite to use the Graph API ‘might’ work. That would be a project on its own

@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 }

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