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,
)

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.

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:

md-to-telegraph article.md --access-token "$TELEGRAPH_API_TOKEN"
cat article.md | 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:

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

md_to_telegraph-0.1.3.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

md_to_telegraph-0.1.3-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file md_to_telegraph-0.1.3.tar.gz.

File metadata

  • Download URL: md_to_telegraph-0.1.3.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.2 {"installer":{"name":"uv","version":"0.12.2","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}

File hashes

Hashes for md_to_telegraph-0.1.3.tar.gz
Algorithm Hash digest
SHA256 4899c1d1e9a16991c4e22117cdc9a84ecc1fd8dcb9b871de7321070798e23af4
MD5 820e10e6b6061068c1ed41b7ab2b16d1
BLAKE2b-256 f1e7fca6b694db3208585b9c9192543b54a0decf89df275262cbbb27caf4d609

See more details on using hashes here.

File details

Details for the file md_to_telegraph-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: md_to_telegraph-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.2 {"installer":{"name":"uv","version":"0.12.2","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}

File hashes

Hashes for md_to_telegraph-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d9933d9f4f3900d0bca92afd30118a53676a2f1ca2cf90cbd2b5336d6532dc07
MD5 d0aa4e882cf1e53cbd4a6d8abb6158a8
BLAKE2b-256 f8b59d2243ca4b3832f792fb617ad837feb8617f83fddaeaf5d1fbaad469ba32

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.8

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

This release

0.1.3 This release

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 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