Skip to main content

A Python CLI package to sync markdown files to Notion and other platforms

Project description

mdsync

Python Version License Code style: ruff Type checked: mypy Tests Coverage

A Python CLI package to sync markdown files to Notion (and potentially other platforms in the future). One-way sync from markdown to platform with focus on simplicity and excellent markdown parsing.

Features

  • One-way sync (markdown → platform)
  • Dry-run mode to preview changes
  • Command-line focused (simple args, no config files)
  • Excellent markdown parsing with LaTeX support
  • Preserve directory structure as nested pages

Installation

From PyPI

pip install mdsync

Quick Start

Prerequisites

  1. Create a Notion integration at https://www.notion.so/my-integrations
  2. Copy the integration token (starts with ntn_)
  3. Share a Notion page with your integration
  4. Copy the page ID from the URL (the last part after the page name)

Usage

Sync a single markdown file:

mdsync notion --token ntn_... --parent PAGE_ID document.md

Sync an entire directory (preserves folder structure):

mdsync notion --token ntn_... --parent PAGE_ID docs/

Preview changes without syncing (dry-run):

mdsync notion --token ntn_... --parent PAGE_ID --dry-run docs/

Command-Line Options

Usage: mdsync [OPTIONS] COMMAND [ARGS]...

  Sync markdown files to various platforms.

  Use platform-specific subcommands (e.g., 'notion') to sync to different
  platforms.

Commands:
  notion  Sync markdown files to Notion

Usage: mdsync notion [OPTIONS] PATH

  Sync markdown files to Notion.

  PATH can be a single markdown file or a directory containing markdown
  files. Directories are synced recursively, preserving the folder structure.

Options:
  --token TEXT       Notion integration token  [required]
  --parent TEXT      Parent page ID where files will be synced  [required]
  --dry-run          Preview changes without actually syncing
  --page-icon        Add random emoji icons to pages
  --page-title TEXT  How to determine page titles: 'heading' (from first heading) or 'filename' (from file/folder name)  [default: filename]
  --help             Show this message and exit.

Supported Markdown Features

  • Headings (H1, H2, H3, H4+ mapped to H3)
  • Paragraphs with inline formatting:
    • Bold
    • Italic
    • Strikethrough
    • Inline code
    • Links
    • Relative links between markdown files (auto-resolved to Notion pages)
  • Code blocks with syntax highlighting
  • Bulleted lists
  • Numbered lists
  • Nested lists
  • Task lists (- [ ] and - [x])
  • Blockquotes
  • Tables with header detection
  • Dividers/Horizontal rules
  • LaTeX equations ($...$ inline, $$...$$ block)
    • Note: Dollar signs are treated as math delimiters. To use $ for currency, escape it: \$4000
  • Line breaks

How It Works

  1. File Discovery: Finds all .md and .markdown files in the specified path
  2. Parsing: Uses mistletoe to parse markdown into an AST
  3. Conversion: Transforms AST nodes to Notion block format
  4. Sync: Creates pages in Notion with proper hierarchy
  5. Link Resolution: Two-pass sync automatically resolves relative links between markdown files to Notion page URLs
  6. Output: Shows progress and summary with beautiful terminal output

Directory Structure Mapping

Folders are converted to nested pages in Notion:

docs/
├── Getting Started.md       →  Page: "Getting Started"
├── guides/                  →  Page: "Guides" (container)
│   ├── Installation.md      →    └─ Page: "Installation"
│   └── Configuration.md     →    └─ Page: "Configuration"
└── api/                     →  Page: "Api" (container)
    ├── Authentication.md    →    └─ Page: "Authentication"
    └── Endpoints.md         →    └─ Page: "Endpoints"

Roadmap

Implemented Features

  • LaTeX math equation support (inline and block)
  • Relative link resolution between markdown files
  • Task list support
  • Strikethrough text support
  • Nested lists
  • Custom page icons (emoji)
  • Configurable page title source (heading vs filename)

Future Features

  • Additional platforms (Confluence, WordPress, Medium)
  • Incremental sync / update detection
  • Image upload support

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see the LICENSE file for details.

Acknowledgments

  • mistletoe - Excellent markdown parser
  • click - Beautiful CLI framework
  • rich - Terminal output formatting

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mdsync-0.1.3.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mdsync-0.1.3-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file mdsync-0.1.3.tar.gz.

File metadata

  • Download URL: mdsync-0.1.3.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mdsync-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d075307e8e9e4a91f5ddbaf608c52f2909094859723d6d926db19a1f74d90ade
MD5 3d0a35c0c5cf3ec8bd5dcd80049577c3
BLAKE2b-256 438eeddfe31a6a11f243a5ce7d96b25dc6c9caa4242905c7db39f249e7251d0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdsync-0.1.3.tar.gz:

Publisher: publish.yml on alasdairpan/mdsync

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mdsync-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: mdsync-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 27.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mdsync-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 308e01530c04dac03ae71151b80611561cf3b2f1bab84ee7fcc1fe3cfbff3c4b
MD5 8ed2bee7213861058940a1294626c7ec
BLAKE2b-256 8510b6457fccd67f144d1ee17eb423611f4cd169990d8293b15c837ef1f00a1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdsync-0.1.3-py3-none-any.whl:

Publisher: publish.yml on alasdairpan/mdsync

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page