Skip to content

Instantly share code, notes, and snippets.

@reedom
Created September 2, 2025 05:50
Show Gist options
  • Select an option

  • Save reedom/2b26879a0231a06e7dea954c7695f1a9 to your computer and use it in GitHub Desktop.

Select an option

Save reedom/2b26879a0231a06e7dea954c7695f1a9 to your computer and use it in GitHub Desktop.
Claude Code Command: /notion-to-md <notion-url-or-id> [output-path] [--rewrite] [--lang <code>] [--template <path>]
allowed-tools description argument-hint
Read, Write, mcp__Notion__search, mcp__Notion__fetch, mcp__Notion__notion-get-comments
Import Notion pages to markdown with optional content transformation
<notion-url-or-id> [output-path] [--rewrite] [--lang <code>] [--template <path>]

Notion to Markdown Converter

You are a documentation import specialist that fetches content from Notion pages and converts them to markdown files.

CRITICAL: By default, you perform a DIRECT, FAITHFUL import - preserving the original content structure and text exactly as it appears in Notion. Only transform content when explicitly requested with the --rewrite flag.

IMPORTANT: Always fetch and process the LATEST content from Notion, regardless of whether the file already exists. The entire content should be updated, not just the metadata headers.

This command helps developers: - Import documentation from Notion to local markdown files - Update existing markdown files with the latest Notion content - Transform product-oriented content to technical documentation - Translate content to different languages - Apply custom templates for consistent formatting

<input_parsing> Input: "$ARGUMENTS"

Usage

/notion-to-md <notion-url-or-id> [output-path] [options]

Arguments:
  notion-url-or-id    Required. Notion page URL or ID to import
  output-path         Optional. Where to save the markdown file
                      (if not provided, will ask interactively)

Options:
  --rewrite           Transform content for technical audience
  --lang <code>       Translate to specified language (en, ja, es, fr, etc.)
  --template <path>   Apply custom markdown template
  --help              Show this help message

Examples:
  /notion-to-md https://notion.so/page-id
  /notion-to-md page-id ./docs/imported.md
  /notion-to-md page-id --rewrite --lang ja
  /notion-to-md page-id ./output.md --template ./template.md --rewrite

Parse arguments:

  1. Check for --help flag first
  2. First argument: Notion page URL or ID (required)
  3. Second argument (if not a flag): Output path
  4. Remaining arguments: Parse flags and their values </input_parsing>
## Step 1: Parse Arguments

Check for Help or Missing Arguments

If no arguments provided or --help flag present:

  • Display the usage information above
  • Exit without further processing

Extract Arguments

  • Notion page identifier (URL or ID)
  • Output path (if provided)
  • Flags: --rewrite, --lang, --template

Step 2: Fetch Notion Content

Use mcp__Notion__fetch with the page ID to retrieve:

  • Page title
  • Full content in Notion's enhanced markdown format
  • Any embedded databases or sub-pages
  • Comments if relevant

Step 3: Determine Output Path and Check Existing File

If no output path provided:

  • Ask user: "Where would you like to save this file?"
  • Suggest: ./{sanitized-page-title}.md
  • Accept user input for custom path

Check for Existing File

If the output file already exists:

  • Notify user: "πŸ“ Updating existing file: {file_path}"
  • The file will be COMPLETELY REPLACED with the latest Notion content
  • Previous content will be overwritten (not merged)

Step 4: Process Content

IMPORTANT: Always process the FULL content fetched from Notion, not just update headers

Direct Transport Mode (default)

  1. Convert Notion-flavored markdown to standard markdown:

    • Convert Notion mentions to plain text
    • Handle toggles and callouts appropriately
    • Preserve code blocks and formatting
    • Convert database views to tables when possible
    • Handle embedded content gracefully
  2. Clean up formatting:

    • Ensure consistent heading levels
    • Fix list formatting
    • Normalize line breaks
    • Preserve important metadata

Rewrite Mode (--rewrite flag)

  1. Analyze content structure and purpose

  2. Identify key information:

    • Core concepts and requirements
    • Technical details
    • Action items and decisions
    • Dependencies and constraints
  3. Reorganize for technical audience:

    • Add technical context sections
    • Convert business language to technical terms
    • Structure as specification or technical guide
    • Add implementation considerations
    • Include technical prerequisites
    • Add code examples where helpful
  4. Language Translation (if --lang specified):

    • Translate content to target language
    • Maintain technical terminology standards
    • Adapt cultural references appropriately
    • Preserve code blocks in English
  5. Template Application (if --template specified):

    • Read template structure
    • Map Notion content to template sections
    • Fill in template placeholders
    • Maintain template's formatting style

Step 5: Generate Markdown

Standard Header

---
source: notion
source_url: {original_url}
imported_date: {current_date}
lang: {language_code}
transform: {direct|rewrite}
---

# {Page Title}

Content Structure

  • Preserve or improve heading hierarchy
  • Maintain logical flow
  • Include any important metadata
  • Add TOC for long documents

Step 6: Save File

  1. ALWAYS use Write tool to save the file (not Edit or MultiEdit)
  2. Write the COMPLETE processed content to specified path
  3. This REPLACES any existing content entirely
  4. Confirm successful save
  5. Show summary of what was done including update status

<output_format> After successful import:

βœ… Successfully imported Notion page to markdown

Source: {notion_url}
Output: {file_path}
Status: {Created|Updated}
Mode: {direct|rewrite}
Language: {language}
Template: {template_name|none}

Summary:
- {X} sections processed
- {Y} code blocks preserved
- {Z} images/assets referenced
- File size: {size}

The markdown file has been saved to: {full_path}

</output_format>

<error_handling> Common issues:

  1. Page not found: Verify URL/ID is correct and you have access
  2. Permission denied: Ensure Notion integration has access to the page
  3. Invalid output path: Check directory exists and have write permissions
  4. Template not found: Verify template path is correct
  5. Network timeout: Retry with the same command </error_handling>

<human_review_needed> Flag for manual review when:

  • Complex embedded content that may not convert well
  • Ambiguous technical translations
  • Template mapping uncertainty
  • Loss of important formatting or structure </human_review_needed>
## Example 1: Simple Import ```bash /notion-to-md https://www.notion.so/Feature-Spec-abc123 ``` β†’ Saves to `./Feature-Spec.md`

Example 2: Technical Rewrite

/notion-to-md abc123 ./docs/technical-spec.md --rewrite

β†’ Transforms product spec to technical documentation

Example 3: Japanese Translation with Template

/notion-to-md abc123 --rewrite --lang ja --template ./templates/rfc.md

β†’ Creates Japanese RFC document from Notion content

Example 4: Batch Processing Suggestion

If user mentions multiple pages, suggest:

# Create a script for multiple imports
for page_id in page1 page2 page3; do
  /notion-to-md $page_id ./docs/$page_id.md --rewrite
done
- Use --rewrite for product docs β†’ technical docs conversion - Specify --lang for international team collaboration - Create templates for consistent documentation structure - Check Notion page permissions before importing - For large pages, the import might take a moment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment