md-to-telegraph
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,
)
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.
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="…"> |
 |
<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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file md_to_telegraph-0.1.1.tar.gz.
File metadata
- Download URL: md_to_telegraph-0.1.1.tar.gz
- Upload date:
- Size: 6.2 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e9684fdb8bdef122600dfbbada0cb6285a1c0cd2914837d7fb8bd70303b8b56
|
|
| MD5 |
fa18900e6dbac837fcf585a361c0ccf8
|
|
| BLAKE2b-256 |
e9f970de43e8a6fd3ae1cb4a672f774bfe0e0a769a570eb95257aa9f91797c54
|
File details
Details for the file md_to_telegraph-0.1.1-py3-none-any.whl.
File metadata
- Download URL: md_to_telegraph-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.4 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5831518d859e910533c303e1066cd35baa75dcd800ab12d571606db9c436ead4
|
|
| MD5 |
221d435d5f91c7e2a94d4b25d9c18e3f
|
|
| BLAKE2b-256 |
c3b5d9ecdd9b5247b55d30a6970c582f3658ef871b2b87bd6ab48088aca22376
|