Skip to content

mkdocs_to_confluence.exporter

Export Confluence-formatted content to local filesystem in dry-run mode.

PageMetadata dataclass

PageMetadata(
    title: str,
    parent: str | None,
    space: str,
    attachments: list[str] = list(),
    confluence_body: str = "",
)

Metadata for a Confluence page export.

Attributes:

Name Type Description
title str

Page title

parent str | None

Direct parent page title

space str

Confluence space key

attachments list[str]

List of attachment file paths

confluence_body str

The Confluence-formatted HTML content

to_dict

to_dict() -> dict[str, Any]

Convert metadata to dictionary for JSON serialization.

Source code in src/mkdocs_to_confluence/exporter.py
def to_dict(self) -> dict[str, Any]:
    """Convert metadata to dictionary for JSON serialization."""
    return {
        "title": self.title,
        "parent": self.parent,
        "space": self.space,
        "attachments": self.attachments,
    }

ConfluenceExporter

ConfluenceExporter(export_dir: Path)

Export Confluence-formatted pages to local filesystem.

Creates a hierarchical directory structure that mirrors the Confluence page hierarchy, making it easy to review content before actual upload.

Initialize exporter with target directory.

Parameters:

Name Type Description Default
export_dir Path

Root directory for exported content

required
Source code in src/mkdocs_to_confluence/exporter.py
def __init__(self, export_dir: Path):
    """Initialize exporter with target directory.

    Args:
        export_dir: Root directory for exported content

    """
    self.export_dir = Path(export_dir)
    self.pages: dict[str, PageMetadata] = {}
    self.page_hierarchy: dict[str, list[str]] = {}

add_page

add_page(
    title: str,
    parent: str | None,
    space: str,
    confluence_body: str,
    attachments: list[str] | None = None,
) -> None

Add a page to the export queue.

Parameters:

Name Type Description Default
title str

Page title

required
parent str | None

Direct parent page title (None for root pages)

required
space str

Confluence space key

required
confluence_body str

The Confluence-formatted HTML content

required
attachments list[str] | None

Optional list of attachment file paths

None
Source code in src/mkdocs_to_confluence/exporter.py
def add_page(
    self,
    title: str,
    parent: str | None,
    space: str,
    confluence_body: str,
    attachments: list[str] | None = None,
) -> None:
    """Add a page to the export queue.

    Args:
        title: Page title
        parent: Direct parent page title (None for root pages)
        space: Confluence space key
        confluence_body: The Confluence-formatted HTML content
        attachments: Optional list of attachment file paths

    """
    metadata = PageMetadata(
        title=title,
        parent=parent,
        space=space,
        attachments=attachments or [],
        confluence_body=confluence_body,
    )
    self.pages[title] = metadata

    # Track hierarchy for directory structure
    if parent:
        if parent not in self.page_hierarchy:
            self.page_hierarchy[parent] = []
        self.page_hierarchy[parent].append(title)

export_all

export_all() -> None

Export all queued pages to the filesystem.

Creates the complete directory structure and writes all pages, metadata, and attachments.

Source code in src/mkdocs_to_confluence/exporter.py
def export_all(self) -> None:
    """Export all queued pages to the filesystem.

    Creates the complete directory structure and writes all pages,
    metadata, and attachments.
    """
    # Clean and create export directory
    if self.export_dir.exists():
        shutil.rmtree(self.export_dir)
    self.export_dir.mkdir(parents=True, exist_ok=True)

    # Export each page
    for title in self.pages:
        self._export_page(title)

    # Write overall metadata summary
    summary = {
        "total_pages": len(self.pages),
        "pages": [
            {
                "title": title,
                "parent": metadata.parent,
                "space": metadata.space,
                "path": str(self._get_page_path(title).relative_to(self.export_dir)),
            }
            for title, metadata in self.pages.items()
        ],
    }

    metadata_file = self.export_dir / "metadata.json"
    metadata_file.write_text(
        json.dumps(summary, indent=2, ensure_ascii=False),
        encoding="utf-8",
    )