Skip to main content

Sync Markdown documentation to Confluence Cloud

Project description

md2confluence

md2confluence

Python PyPI Version License: MIT

A Python tool to sync Markdown documentation to Confluence Cloud.

Features

  • Markdown to Confluence conversion - Headers, lists, tables, code blocks, info panels, task lists, and more
  • Front-matter support - Per-document settings via YAML/JSON front-matter
  • Emoji shortcodes - :smile: → 😄, :rocket: → 🚀
  • Subscript/superscript - H~2~O → H₂O, x^2^ → x²
  • Page labels - Set Confluence labels via front-matter tags
  • Image handling - Automatically uploads local images as attachments
  • Local output mode - Generate Confluence Storage Format files without API calls
  • Config-driven - Define document mappings in a simple config file
  • Dry-run mode - Preview changes before syncing
  • Retry logic - Exponential backoff for transient failures
  • Rate limiting - Avoid API throttling

Installation

# From PyPI (recommended)
pip install md2confluence

# For development
git clone <repository-url>
cd md2confluence
pip install -e .

Dependencies

  • Python 3.9+
  • requests library (installed automatically)

Quick Start

  1. Create an API token (see Authentication below)

  2. Set environment variables:

    export CONFLUENCE_API_TOKEN="your-api-token"
    export CONFLUENCE_USER_EMAIL="your-email@example.com"
    
  3. Create a config file (.confluence-sync.conf):

    CONFLUENCE_BASE_URL="https://your-domain.atlassian.net/wiki"
    CONFLUENCE_SPACE_KEY="DOCS"
    CONFLUENCE_TECH_PARENT_ID="123456789"
    
    # Document mappings: "Title|path/to/file.md|parent_page_id"
    CONFLUENCE_DOC_README="README|README.md|${CONFLUENCE_TECH_PARENT_ID}"
    
  4. Run the sync:

    md2confluence
    

Usage

# Sync all configured documents
md2confluence

# Dry-run (preview without changes)
md2confluence --dry-run

# List configured documents
md2confluence --list

# Verify config and connectivity
md2confluence --verify

# Sync a single document
md2confluence --single "Page Title" path/to/doc.md parent_page_id

# Convert markdown to Confluence format (stdout)
echo "# Hello" | md2confluence --stdin

# Local output (generate .csf files without API calls)
md2confluence --local ./output

Authentication

Creating an API Token

  1. Go to Atlassian API Tokens
  2. Click Create API token
  3. Enter a label (e.g., "md2confluence") and click Create
  4. Copy the token immediately (you won't see it again)

Required Permissions

The user account associated with the API token needs:

  • Space permissions:

    • View space
    • Add pages
    • Update pages
    • Add attachments
  • Page permissions:

    • View, Edit on target pages/parent pages

For organization-managed accounts, ensure the user has appropriate Confluence access in your Atlassian admin settings.

Auth Modes

Mode Variables Required Use Case
Basic CONFLUENCE_USER_EMAIL + CONFLUENCE_API_TOKEN Standard Atlassian Cloud
Bearer CONFLUENCE_API_TOKEN only OAuth tokens, service accounts

Auth mode is auto-detected based on whether CONFLUENCE_USER_EMAIL is set.

Configuration

See confluence-sync.conf.example for all available options.

Document Mappings

Define documents to sync using CONFLUENCE_DOC_* variables:

CONFLUENCE_DOC_MYPAGE="Page Title|path/to/file.md|parent_page_id"

Edge Case Handling

Option Values Default
CONFLUENCE_MISSING_FILE_BEHAVIOR skip, fail skip
CONFLUENCE_IMAGE_FAILURE_BEHAVIOR placeholder, skip, fail placeholder
CONFLUENCE_TITLE_SPECIAL_CHARS sanitize, encode, fail sanitize

Front-Matter

Documents can include YAML or JSON front-matter to override settings:

---
title: Custom Page Title
tags: [documentation, api, v2]
space: DOCS
parent_id: "123456789"
add_disclaimer: false
max_image_width: 600
synchronized: true
---

# Document content starts here

Supported Front-Matter Fields

Field Type Description
title string Override page title
tags / labels array Confluence page labels
space / space_key string Target Confluence space
parent_id / parent string Parent page ID
add_disclaimer boolean Add auto-generated notice
max_image_width integer Image width constraint (px)
image_failure_behavior string Override error handling
title_special_chars string Override title sanitization
synchronized / sync boolean Set false to skip document

Front-matter settings take precedence over config file and environment variables.

Markdown Support

  • Headers (h1-h6)
  • Bold, italic, strikethrough
  • Subscript (~text~) and superscript (^text^)
  • Ordered and unordered lists
  • Nested lists
  • Task lists (checkboxes)
  • Tables
  • Fenced code blocks with syntax highlighting
  • Inline code
  • Links (inline and reference-style)
  • Images (uploaded as attachments)
  • Blockquotes → Confluence panels (Note/Warning/Tip/Info)
  • Horizontal rules
  • Emoji shortcodes (:smile:, :rocket:, :thumbsup:, etc.)

License

MIT

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

md2confluence-1.1.2.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

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

md2confluence-1.1.2-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file md2confluence-1.1.2.tar.gz.

File metadata

  • Download URL: md2confluence-1.1.2.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for md2confluence-1.1.2.tar.gz
Algorithm Hash digest
SHA256 68dac5ea17fbf4ef4d2df7190eb42cf1c636d863bc3ff3a2445651e62a75167a
MD5 62b245757addabc0a104f4147a7654cf
BLAKE2b-256 32451677e365bb959813f74d68d74850e101c2f753994c47588d359856ffbc7a

See more details on using hashes here.

File details

Details for the file md2confluence-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: md2confluence-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 23.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for md2confluence-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 377679bc2d2c6aaa1e70291543d83f5039eb2be90a7abc47a9c52f886b742744
MD5 75fdb5efa4e25d8b981d116e648d0779
BLAKE2b-256 c18b383a8919f45b2a987e6f34d163d63bfd22b66f18af07d5a5536ede70ba1b

See more details on using hashes here.

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