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

This project requires Python 3.10+ and uv for development.

Clone the repo and install dependencies:

uv pip install -e .

Usage

Basic Example

from richtextjson2typst import convert

# Example: Quill JSON
quill_json = {"ops": [{"insert": "Hello", "attributes": {"bold": True}}]}
typst = convert(quill_json, "quill")
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.0.tar.gz (4.0 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.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for richtext_typst-0.1.0.tar.gz
Algorithm Hash digest
SHA256 183874221887f159c38b3126d9f653aad2f7034b1bc3f999ad4e1b88404129cc
MD5 594c3343d0b93cef69d9c1f7ea60d7a1
BLAKE2b-256 bbc47694477fec8ed3318e90ce46f53701d2d9bfca767e74e4cd8c53beb10b30

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for richtext_typst-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bc197b5b34f98052f7ef1ea92e82d53380ddf0f802fcbcbe2fb052fd2a3975fe
MD5 feec2b2610a449f4f6fa61788e10c662
BLAKE2b-256 4ca5b99c5e5bc395293968e71513b60c84e2d719ae7c268d3162d8e5ebe02482

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