๐ช Convert Markdown into Notion Blocks
MIT License
Seamlessly Convert Markdown to Notion Blocks
NotionMD is a powerful Go package that bridges the gap between Markdown and Notion. It allows you to effortlessly convert your Markdown content into Notion blocks, making it easier than ever to integrate your existing Markdown documents into your Notion workspace.
Get started with NotionMD in your Go project:
go get github.com/brittonhayes/notionmd
Here's a simple example of how to use NotionMD:
package main
import (
"encoding/json"
"log"
"fmt"
"github.com/brittonhayes/notionmd"
)
func main() {
markdown := `
# Welcome to NotionMD
- Convert Markdown easily
- Integrate with Notion seamlessly`
blocks, err := notionmd.Convert(markdown)
if err != nil {
log.Fatal(err)
}
// Print the resulting Notion blocks
result, _ := json.MarshalIndent(blocks, "", " ")
fmt.Println(string(result))
}
[
{
"heading_1": {
"rich_text": [
{
"type": "text",
"plain_text": "Welcome to NotionMD",
"text": {
"content": "Welcome to NotionMD"
}
}
],
"is_toggleable": false
}
},
{
"bulleted_list_item": {
"rich_text": [
{
"type": "text",
"plain_text": "Convert Markdown easily",
"text": {
"content": "Convert Markdown easily"
}
}
]
}
},
{
"bulleted_list_item": {
"rich_text": [
{
"type": "text",
"plain_text": "Integrate with Notion seamlessly",
"text": {
"content": "Integrate with Notion seamlessly"
}
}
]
}
}
]
This example demonstrates how to create a Notion page using the blocks parsed from a Markdown document
package main
import (
"context"
"log"
"os"
"github.com/brittonhayes/notionmd"
"github.com/dstotijn/go-notion"
)
func main() {
// Read the Markdown file
markdown, err := os.ReadFile("example.md")
if err != nil {
log.Fatalf("Error reading Markdown file: %v", err)
}
// Convert the Markdown content to Notion blocks
blocks, err := notionmd.Convert(string(markdown))
if err != nil {
log.Fatalf("Error converting Markdown to Notion blocks: %v", err)
}
// Initialize the Notion client
client := notion.NewClient(os.Getenv("NOTION_API_KEY"))
// Create a new page in Notion
parentPageID := "your-parent-page-id" // Replace with your actual parent page ID
newPage, err := client.CreatePage(context.Background(), notion.CreatePageParams{
ParentType: notion.ParentTypePage,
ParentID: parentPageID,
Title: []notion.RichText{
{
Text: ¬ion.Text{
Content: "Markdown to Notion Example",
},
},
},
Children: blocks,
})
if err != nil {
log.Fatalf("Error creating Notion page: %v", err)
}
log.Printf("Successfully created Notion page with ID: %s", newPage.ID)
}
[!NOTE] Make sure to set the
NOTION_API_KEY
environment variable with your Notion API key and replace"your-parent-page-id"
with the actual ID of the parent page where you want to create the new page.
Ensure the reliability of NotionMD by running the test suite:
go test ./... -v -cover
We welcome contributions from the community! If you'd like to contribute:
Please open an issue if you find a bug or have a feature request.
NotionMD is open-source software licensed under the MIT License. See the LICENSE file for details.
For detailed API documentation and advanced usage examples, visit our Go Package Documentation.
Built with ๐ค by Britton Hayes and contributors. If you find NotionMD useful, consider giving it a star on GitHub!