Skip to main content

Convert Rich Text JSON to Typst

Project description

Rich Text JSON to Typst Converter

Convert rich text JSON documents (from editors like ProseMirror, Quill, Slate) to Typst markup.

Features

  • Supports multiple formats: Quill, Slate, ProseMirror (extensible)
  • Simple API: One function to convert any supported format
  • Custom parser support: Register your own parser for new formats

Installation

pip install richtext-typst

Usage

Basic Example

from richtext_typst import convert

# Example: ProseMirror JSON
prosemirror_json = {
  "type": "doc",
  "content": [
    {"type": "paragraph", "content": [
      {"type": "text", "text": "Hello", "marks": [{"type": "bold"}]}
    ]}
  ]
}
typst = convert(prosemirror_json, "prosemirror")
print(typst)  # Output: *Hello*

Supported Formats

API

convert(data: dict, fmt: str | BaseParser) -> str

  • data: The rich text JSON object
  • fmt: Format name ("quill", "slate", "prosemirror") or a custom parser instance
  • Returns: Typst markup as a string

Registering a Custom Parser

from richtextjson2typst import register_parser, BaseParser

class MyParser(BaseParser):
		def parse(self, data: dict) -> str:
				return f"#myformat[{data['text']}]
"
register_parser("myformat", MyParser())

Testing

Run all tests:

uv run pytest

Project Structure

  • src/richtextjson2typst/ — Main package
    • converter.py — Format dispatch and API
    • base.py — Parser interface
    • exceptions.py — Error types
    • formats/ — Built-in format parsers (Quill, Slate, ProseMirror)
  • tests/ — Unit and robustness tests

License

MIT License. See LICENSE.

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

richtext_typst-0.1.1.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

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

richtext_typst-0.1.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file richtext_typst-0.1.1.tar.gz.

File metadata

  • Download URL: richtext_typst-0.1.1.tar.gz
  • Upload date:
  • Size: 27.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.18

File hashes

Hashes for richtext_typst-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8fac0e3b9864d484dad227a6346ff148846218a122eef7276e1605b04b6aa41a
MD5 8e80d066209602c436d5851cb0632165
BLAKE2b-256 a2737f76f527e004b8b50b179babd8e419e8b0b4b735f6f460ae27c8622a1789

See more details on using hashes here.

File details

Details for the file richtext_typst-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for richtext_typst-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 41ce71bc80d892d3a2021b3a7eb891dcc5929e9123c36bed257494cd9c1a162e
MD5 a59cf6c0176d138ca303a06ae5bdda3b
BLAKE2b-256 84e23d167d31efeb9cf59c5ad0aa4b8ce9225a6870f98efa464cda2594ed1d84

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