Skip to main content

md-to-telegraph

PyPI

Convert Markdown text into Telegraph DOM nodes and publish pages through the Telegraph API.

Overview

md-to-telegraph transforms a Markdown string into a list of Telegraph-compatible DOM node dicts, suitable for use with the Telegraph API.

Telegraph nodes follow this structure:

{
  "tag": "p",
  "attrs": {"href": "..."},
  "children": ["text", {"tag": "strong", "children": ["bold"]}]
}

Installation

uv add md-to-telegraph

Usage

from md_to_telegraph import md_to_telegraph

nodes = md_to_telegraph("# Hello\n\nThis is **bold** text.")
# [
#   {"tag": "h3", "children": ["Hello"]},
#   {"tag": "p", "children": ["This is ", {"tag": "strong", "children": ["bold"]}, " text."]}
# ]

For extracted content that may need a plain-text fallback, use content_to_telegraph:

from md_to_telegraph import content_to_telegraph

nodes = content_to_telegraph(content_markdown, fallback_text)

To create a page directly, use create_page. The default performs one API request; pass retry_attempts to retry transient failures:

from md_to_telegraph import create_page

url = create_page(
    access_token="telegraph-token",
    title="An article",
    content_markdown=content_markdown,
    fallback_text=fallback_text,
    source_url="https://example.com/article",
    retry_attempts=3,
)

For content that may exceed Telegraph's page size, use create_pages. It splits Markdown between complete blocks (without cutting paragraphs, fenced code, or other Markdown constructs), creates linked pages with previous/next navigation, and returns all URLs plus their Markdown chunks:

from md_to_telegraph import create_pages

pages = create_pages(access_token="telegraph-token", title="A long article", content_markdown=content_markdown)
first_url = pages.urls[0]

create_page reads YAML front matter from content_markdown. When these arguments are omitted, it uses title, author, and url from the header; explicit arguments always take precedence. The date field is preserved as metadata but Telegraph has no native page-date field. When an author is not available, the source URL's domain is used as the author name, while the complete source URL is sent as author_url.

When the front matter declares a non-document page type such as website, home, collection, or search, create_page refuses to publish it. This prevents accidentally turning site home pages and listings into Telegraph articles.

The same operation is available as a command-line tool. A file uses its stem as the default title; stdin uses its first Markdown heading, or accepts an explicit --title:

uvx md-to-telegraph article.md --access-token "$TELEGRAPH_API_TOKEN"
cat article.md | uvx md-to-telegraph --title "An article"

The token can be passed with --access-token or read from TELEGRAPH_API_TOKEN. To create a new Telegraph account explicitly and use its token for the page, add --create-account (optionally with --short-name). The account creation uses Telegraph's createAccount method.

To create only a token, use the create-account subcommand. It prints a shell assignment and does not publish a page:

uvx md-to-telegraph create-account --short-name lobstersgram
export $(md-to-telegraph create-account --short-name lobstersgram)

The output can also be appended to a shell startup file:

echo "export $(md-to-telegraph create-account --short-name lobstersgram)" >> ~/.bashrc

Markdown features supported

Markdown element Telegraph output
# Heading 1 <h3>
## Heading 2 <h4>
### Heading 3+ <p><strong>…</strong></p>
**bold** <strong>
*italic* <em>
`code` <code>
~~strike~~ <del>
[text](url) <a href="…">
<url> <a href="…">
![alt](url) <img src="…">
```lang\ncode\n``` <pre><code>
> quote <blockquote>
- item / 1. item <ul> / <ol>
--- <hr>
hard line break ( ) <br>
soft line break space

Development

uv run pytest

License

MIT

Metadata

Release files for md-to-telegraph 0.1.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for md-to-telegraph 0.1.10
File Size Uploaded
md_to_telegraph-0.1.10.tar.gz 9.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for md-to-telegraph 0.1.10
File Interpreter ABI Platform
md_to_telegraph-0.1.10-py3-none-any.whl Python 3 none any Details

Total release size: 22.4 kB

Release files / md_to_telegraph-0.1.10.tar.gz

Download URL md_to_telegraph-0.1.10.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f9cae3e0cc1958d1c55db4065719732d4fc2754beae9f70fa83f14648dfab8e4
BLAKE2b-256 checksum
How to use checksums
cd6b11ba59d89688dfccced3434a1f0935f510ab8ded0ba9744f62875218a947
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / md_to_telegraph-0.1.10-py3-none-any.whl

Download URL md_to_telegraph-0.1.10-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dd32232e6c4c2e22cc8c151040b1105bcb5fe69c0c9b27fbda21da6f5397cf72
BLAKE2b-256 checksum
How to use checksums
b12c902640bcb5eeb61a84dece3de712d259e3f8d60def8c8b562673b54d12af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.1.11

2 release files

This release

0.1.10 This release

2 release files

0.1.8

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page