Skip to main content

A Python library for converting Atlassian Document Format (ADF) to Markdown

Project description

pyadf

A Python library for converting Atlassian Document Format (ADF) to Markdown.

Features

  • Class-based API for clean, object-oriented usage
  • Flexible input - accepts JSON strings, dictionaries, or any ADF node type
  • Comprehensive node support:
    • Text formatting (bold, italic, links)
    • Headings (h1-h6)
    • Lists (bullet, ordered, task lists)
    • Tables with headers and column spans
    • Code blocks with syntax highlighting
    • Blockquotes and panels
    • Status badges
    • Inline cards
    • Emoji (unicode and shortName)
    • Mentions
  • Type-safe with comprehensive type hints and Python 3.11+ support
  • Extensible architecture with registry pattern for custom node types
  • Robust error handling with detailed, context-aware error messages
  • Debug mode for troubleshooting and development

Installation

pip install pyadf

Usage

Basic Usage

from pyadf import Document

# Convert ADF document to markdown
adf_data = {
    "type": "doc",
    "content": [
        {
            "type": "paragraph",
            "content": [
                {"type": "text", "text": "Hello, "},
                {"type": "text", "text": "world!", "marks": [{"type": "strong"}]}
            ]
        }
    ]
}

doc = Document(adf_data)
markdown_text = doc.to_markdown()
print(markdown_text)
# Output: Hello, **world!**

Converting from JSON String

from pyadf import Document

# Convert from JSON string
adf_json = '{"type": "doc", "content": [...]}'
doc = Document(adf_json)
markdown = doc.to_markdown()

Converting Individual Nodes

from pyadf import Document

# Convert a single node (any ADF node type)
node = {
    "type": "heading",
    "attrs": {"level": 2},
    "content": [
        {"type": "text", "text": "My Heading"}
    ]
}

doc = Document(node)
markdown = doc.to_markdown()
print(markdown)
# Output: ## My Heading

Error Handling

The library provides detailed error handling with specific exceptions:

from pyadf import Document, InvalidJSONError, UnsupportedNodeTypeError

try:
    doc = Document('invalid json')
except InvalidJSONError as e:
    print(f"Invalid JSON: {e}")

try:
    doc = Document({"type": "unsupported_type"})
except UnsupportedNodeTypeError as e:
    print(f"Unsupported node: {e}")

Debug Mode

Enable debug mode for detailed logging:

from pyadf import Document, set_debug_mode

set_debug_mode(True)
doc = Document(adf_data)
markdown = doc.to_markdown()

Customizing Markdown Output

Use MarkdownConfig to customize the generated markdown:

from pyadf import Document, MarkdownConfig

doc = Document(adf_data)

# Default bullet marker is +
doc.to_markdown()  # "+ Item 1\n+ Item 2"

# Use * for bullet lists
config = MarkdownConfig(bullet_marker="*")
doc.to_markdown(config)  # "* Item 1\n* Item 2"

# Use - for bullet lists
config = MarkdownConfig(bullet_marker="-")
doc.to_markdown(config)  # "- Item 1\n- Item 2"

Available options:

Option Values Default Description
bullet_marker +, -, * + Character used for bullet list items

Supported ADF Node Types

ADF Node Type Markdown Output Notes
doc Document root Top-level container
paragraph Plain text with newlines
text Text with optional formatting Supports bold, italic, links
heading # Heading (levels 1-6)
bulletList + Item
orderedList 1. Item
taskList - [ ] Task Checkbox tasks
codeBlock ```language\ncode\n``` Optional language syntax
blockquote > Quote
panel > Panel content Info/warning/error boxes
table Markdown table Supports headers and colspan
status **[STATUS]** Status badges
inlineCard [link] or code block Link previews
emoji Unicode emoji
hardBreak Line break
mention @Jirauser Displayname Outputs mentioned Jira user's display name prefixed with an @

Exception Types

The library provides specific exceptions for different error scenarios:

  • PyADFError - Base exception for all pyadf errors
  • InvalidJSONError - Raised when JSON parsing fails
  • InvalidInputError - Raised when input type is incorrect
  • InvalidADFError - Raised when ADF structure is invalid
  • MissingFieldError - Raised when required fields are missing
  • InvalidFieldError - Raised when field values are invalid
  • UnsupportedNodeTypeError - Raised when encountering unsupported node types
  • NodeCreationError - Raised when node creation fails

All exceptions include detailed context about the error location in the ADF tree.

Development

Setting Up Development Environment

# Clone the repository
git clone https://github.com/YoungseokCh/pyadf.git
cd pyadf

# Install in development mode
pip install -e .

Running Tests

pytest

License

MIT License - see LICENSE file for details

Changelog

0.3.1 (Current)

  • Added mention node support

0.3.0

  • Added emoji node support
  • Added configurable bullet markers via MarkdownConfig

0.1.0

  • Class-based API with Document class
  • Better error handling with detailed exceptions and context
  • Support for common ADF node types (doc, paragraph, text, headings, lists, tables, etc.)
  • Type-safe architecture with comprehensive type hints (Python 3.11+)
  • Registry pattern for extensibility
  • Flexible input handling (JSON strings, dictionaries, individual nodes)
  • Debug mode for troubleshooting

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

pyadf-0.3.1.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

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

pyadf-0.3.1-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file pyadf-0.3.1.tar.gz.

File metadata

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

File hashes

Hashes for pyadf-0.3.1.tar.gz
Algorithm Hash digest
SHA256 8843143fdeeb0ef97fbf5634c8f5e0a43d5b30d93687b2a9a465a83372d4dd2f
MD5 cb1c6e53b3e04412a6951b2d490fb758
BLAKE2b-256 bc8e093eb29de564d39bd4f0449c8b81a235f3ff25e5b90d188879d53b9a2ae3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyadf-0.3.1.tar.gz:

Publisher: publish.yml on YoungseokCh/pyadf

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

File details

Details for the file pyadf-0.3.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pyadf-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 96d1c30baaf5ac175a2310db6087b926c333558389f5b92bba7278c464f436b0
MD5 90d1f5a4467cda16659a9d08948608f7
BLAKE2b-256 78637271869454b3243b1eee87f2722ecbc6059eb140b0cbbef854b871c21372

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyadf-0.3.1-py3-none-any.whl:

Publisher: publish.yml on YoungseokCh/pyadf

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