Convert Notion Pages to Markdown
This post has been updated since November 2022 to reflect the changes Notion has gone through since then.
Here Are the Steps
- Go to the top left of you Notion.
- Click ‘Export’.
- Choose your export option and ensure that you have Markdown and CSV selected.
OUTDATED
Last Updated: 2022-11-12
This still works but is no longer the preferred method!
This is the GitHub repo I use for conversions: https://github.com/souvikinator/notion-to-md
One thing to note is that images will be unavailable after ~2-3 days using this method as the buckets Notion uses to store them will have expired. Currently there is no workaround but to either rerun this automatically or manually link your static images to your markdown file.
Prerequisites for this guide:
- You have Node.js installed and configured on your local computer.
- You have a code editor (I use Visual Studio Code).
- You have Notion.
Step 1: Install Notion to Markdown on your Computer
Since I’m kind of dumb when it comes to using repos I just cloned all of the repo onto my personal computer using Git.
1git clone https://github.com/souvikinator/notion-to-md.git
Step 2: Create the Notion to Markdown Integration
-
Go to https://www.notion.so/my-integrations and create a new Integration.
-
Name it how you would like, and associate it with your chosen Notion workspace.
-
Set the Integration to Read content and not to request any user information for privacy.
- Press
Submit
to create the Integration.
- Press
Step 3: Add your Integration to your Notion Workspace
-
Go to the top left of you Notion.
-
Add connections > add your Integration.
Step 4: Convert Notion to Markdown
-
Open the cloned repository in your code editor and navigate/create
test.js
. -
Copy your Integration token. The token would be found on the same page that you created your Integration on Step 2.
-
Add your Integration token secret to box 1, then add your page’s hash to box 2.
1// test.js 2const { Client } = require("@notionhq/client"); 3const { NotionToMarkdown } = require("notion-to-md"); 4// or 5// import {NotionToMarkdown} from "notion-to-md"; 6 7const notion = new Client({ 8auth: "secret_.......", // internal integration token 9}); 10 11// passing notion client to the option 12const n2m = new NotionToMarkdown({ notionClient: notion }); 13 14(async () => { 15const mdblocks = await n2m.pageToMarkdown("cba61......"); // page's hash 16const mdString = n2m.toMarkdownString(mdblocks); 17 18// writing to file 19const fs = require('fs'); 20fs.writeFile("notion-to-markdown-output.md", mdString, (err) => { 21 console.log(err); 22}); 23})();
-
Run the code:
1node test.js
That’s it! Now you can put the Notion content wherever! 🥳