Skip to main content

Bidirectional converter between GitHub Flavored Markdown and Atlassian Document Format

Project description

Marklas

CI PyPI Python License

MarkdownASTADF

Installation

pip install marklas

Usage

Markdown → ADF

from marklas.parser.md import parse
from marklas.renderer.adf import render

doc = parse("**Hello** world")
adf = render(doc)

# {
#   "type": "doc",
#   "version": 1,
#   "content": [
#     {
#       "type": "paragraph",
#       "content": [
#         {"type": "text", "text": "Hello", "marks": [{"type": "strong"}]},
#         {"type": "text", "text": " world"}
#       ]
#     }
#   ]
# }

ADF → Markdown

from typing import Any

from marklas.parser.adf import parse
from marklas.renderer.md import render

adf: dict[str, Any] = {
    "type": "doc",
    "version": 1,
    "content": [
        {
            "type": "paragraph",
            "content": [
                {"type": "text", "text": "Hello", "marks": [{"type": "strong"}]},
                {"type": "text", "text": " world"},
            ],
        }
    ],
}
doc = parse(adf)
md = render(doc)

# "**Hello** world\n"

Conversion Rules

Block

ADF AST Markdown
paragraph Paragraph(children) inline content
heading (level 1-6) Heading(level, children) # ~ ######
codeBlock (language?) CodeBlock(code, language?) ```lang\ncode\n```
blockquote BlockQuote(children) > text
bulletList > listItem BulletList(items) > ListItem(children) - item
orderedList > listItem OrderedList(items, start) > ListItem(children) 1. item
taskList > taskItem BulletList > ListItem(checked=bool) - [x] / - [ ]
decisionList > decisionItem BulletList > ListItem(checked=bool) - [x] / - [ ]
rule ThematicBreak ---
table > tableRow > tableHeader/tableCell Table(head, body, alignments) GFM table
mediaSingle > media (external) Paragraph > Image(url, alt) ![alt](url)
mediaSingle > media (non-external) Paragraph > Text("[Image: id]") [Image: id]
mediaGroup > media Paragraph > Image/Text ![alt](url) / [Image: id]
panel BlockQuote(children) > text
expand / nestedExpand (title?) BlockQuote(children) (title prepended) > title\n> text
layoutSection > layoutColumn flattened blocks columns flattened
blockCard (url) Paragraph > Link(url) [url](url)
embedCard (url) Paragraph > Link(url) [url](url)

Inline

ADF AST Markdown
text Text(text) plain text
text + strong mark Strong(children) **text**
text + em mark Emphasis(children) *text*
text + strike mark Strikethrough(children) ~~text~~
text + code mark CodeSpan(code) `code`
text + link mark Link(url, children, title?) [text](url)
hardBreak HardBreak \ + newline
SoftBreak newline
mention CodeSpan(code) `@user`
emoji Text(text) :shortName:
date CodeSpan(code) `2024-01-01`
status CodeSpan(code) `status text`
inlineCard (url) Link(url) [url](url)
Image(url, alt, title?) ![alt](url)

Not Supported

Element Behavior
ADF marks: underline, textColor, backgroundColor, subsup silently ignored
ADF blocks: extension, bodiedExtension, syncBlock, bodiedSyncBlock [type] placeholder
ADF inlines: placeholder, inlineExtension, mediaInline [type] placeholder
ADF table: colspan, rowspan expanded with empty cells
ADF table: background, colwidth attributes ignored
ADF table: non-paragraph cell content [type] placeholder
Markdown: raw HTML (block, inline) silently ignored

Development

uv sync --extra dev
uv run pytest -v
uv run black src/ tests/

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

marklas-0.1.1.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

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

marklas-0.1.1-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file marklas-0.1.1.tar.gz.

File metadata

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

File hashes

Hashes for marklas-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a4caf77b93a853259c8cfbfa3f58675b164ced845bbe4f90d91a0134d9a326c4
MD5 dbdff3d97e4610b78d28163017ebcdf5
BLAKE2b-256 4356721ba9740dfd8a52fa81f964863c370d4c117255fcc047f8398e812f646a

See more details on using hashes here.

Provenance

The following attestation bundles were made for marklas-0.1.1.tar.gz:

Publisher: publish.yml on byExist/marklas

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

File details

Details for the file marklas-0.1.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for marklas-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c1232e7132eb09460703e1bcb4811a4f241b1f5fc5d192b148c42eb6d8680529
MD5 402fe1a99cbac3c8f7a379d543e32adb
BLAKE2b-256 79dea83385c29dacdbc20079e2411fbc24ab26be8f312a738bc3ea5dcb1a50c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for marklas-0.1.1-py3-none-any.whl:

Publisher: publish.yml on byExist/marklas

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