Skip to main content

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.md for rules and future implementation details
  • Status: baseline working — headings + inline styles (bold/italic/strikethrough/monospace)
  • Parser: markdown-it
  • Python: optional pyo3 bindings behind python feature

Quick Start (Rust)

  • Call render(&str) -> Rendered to get:
    • Rendered.text: String — final message text (headings converted to hN ...).
    • 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 with signal-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 via pyo3 (module scaffolding pending). Build with:
    • cargo build --features python
    • Or install the Python extension via maturin:
      • pip install maturin (once)
      • maturin develop -F python (installs markdownish into your current venv)

Python usage

After maturin develop -F python, try:

  • python scripts/render.py "# **Hello** _world_ and **b** *i*"
    • Outputs JSON with text and textStyles (array of "<start>:<len>:<KIND>").
  • python scripts/repl.py
    • Interactive: type lines, then :go to render current buffer.

Python API (high level):

  • import markdownish; markdownish.render(text: str) -> dict with keys:
    • text: str — final message string
    • textStyles: list[str] — array of "<start>:<len>:<KIND>"

Docs

  • Generate Rust docs: cargo doc --open

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

markdownish-0.1.2.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

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

markdownish-0.1.2-cp313-cp313-manylinux_2_34_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

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

Hashes for markdownish-0.1.2.tar.gz
Algorithm Hash digest
SHA256 bc4867ae6786475475e5ad14c8ef0435088c3bd73966777123d11c7eed0cfd46
MD5 745df38bed61b700e108e184056f2c3c
BLAKE2b-256 40a01d8932794ff8009945bcd921199ea8bfd111dc7073316834815ab49ba4ec

See more details on using hashes here.

File details

Details for the file markdownish-0.1.2-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for markdownish-0.1.2-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 31992cca503e0654dbe5cab56736bfeeb8e4d38fdce126410ef1c75053d41fca
MD5 57e9aa0281ef4345c702c34e4aad073a
BLAKE2b-256 66cd62f8a3dff09194748ef6fca47df765ff24b6d8990f972c3d03eb6560acd9

See more details on using hashes here.

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