Render Markdown-ish to Signal-friendly text and textStyles (usable with signal-cli)
Project description
markdownish
Rust library to render Markdown-ish input into a Signal-friendly plain text message and text style ranges suitable for use with signal-cli.
- Spec: see
spec.mdfor rules and future implementation details - Status: baseline working — headings + inline styles (bold/italic/strikethrough/monospace)
- Parser:
markdown-it - Python: optional
pyo3bindings behindpythonfeature
Quick Start (Rust)
- Call
render(&str) -> Renderedto get:Rendered.text: String— final message text (headings converted tohN ...).Rendered.styles: Vec<TextStyle>— style spans with UTF‑16 offsets.- Encode spans for transport if needed with
encode_text_styles(&rendered.styles)→["<start>:<len>:<KIND>", ...](format usable withsignal-cli).
Example
use markdownish::{render, Style, TextStyle, encode_text_styles};
let rendered = render("# **Hello** _world_\n\nHello **bold** and *it*.");
// rendered.text => "h1 Hello world\n\nHello bold and it."
// rendered.styles => spans for bold/italic in the paragraph (none inside headings)
let encoded = encode_text_styles(&rendered.styles);
println!("{}", rendered.text);
println!("{:?}", encoded);
What gets translated (high level)
- Headings: ATX/Setext →
hN <raw text>plus a blank line after. Inline styles inside headings are not emitted. - Bold/Italic:
**text**/__text__,*text*/_text_→ spans over the inner text. - Paragraphs/Breaks: paragraphs separated by a blank line; soft/hard breaks →
\n. - Newlines: input CR/CRLF normalized to
\n.
Features
python: enables optional Python bindings viapyo3(module scaffolding pending). Build with:cargo build --features python- Or install the Python extension via
maturin:pip install maturin(once)maturin develop -F python(installsmarkdownishinto your current venv)
Python usage
After maturin develop -F python, try:
python scripts/render.py "# **Hello** _world_ and **b** *i*"- Outputs JSON with
textandtextStyles(array of"<start>:<len>:<KIND>").
- Outputs JSON with
python scripts/repl.py- Interactive: type lines, then
:goto render current buffer.
- Interactive: type lines, then
Python API (high level):
import markdownish; markdownish.render(text: str) -> dictwith keys:text: str— final message stringtextStyles: list[str]— array of"<start>:<len>:<KIND>"
Docs
- Generate Rust docs:
cargo doc --open
Project details
Release history Release notifications | RSS feed
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 markdownish-0.1.2.tar.gz.
File metadata
- Download URL: markdownish-0.1.2.tar.gz
- Upload date:
- Size: 21.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc4867ae6786475475e5ad14c8ef0435088c3bd73966777123d11c7eed0cfd46
|
|
| MD5 |
745df38bed61b700e108e184056f2c3c
|
|
| BLAKE2b-256 |
40a01d8932794ff8009945bcd921199ea8bfd111dc7073316834815ab49ba4ec
|
File details
Details for the file markdownish-0.1.2-cp313-cp313-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: markdownish-0.1.2-cp313-cp313-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31992cca503e0654dbe5cab56736bfeeb8e4d38fdce126410ef1c75053d41fca
|
|
| MD5 |
57e9aa0281ef4345c702c34e4aad073a
|
|
| BLAKE2b-256 |
66cd62f8a3dff09194748ef6fca47df765ff24b6d8990f972c3d03eb6560acd9
|