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.2.tar.gz (28.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.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for richtext_typst-0.1.2.tar.gz
Algorithm Hash digest
SHA256 78460f5d4d45d9ca2288f688681b2219ef1cab09cf3ea3eb316faab4b3fdb7cf
MD5 ff1a4f49704907c84ef965e68c4672df
BLAKE2b-256 3cb4b4cf00ef2d799110ab0f63cdffe2fad734010969995a71b4d6a783faff39

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for richtext_typst-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3aea11882db3a5f22c904c98fc07a0320cd99624e9d4ed872c1fd69eb22ca9f0
MD5 d5d3a9c08ee13844eb98d7c91b7ec065
BLAKE2b-256 2653531de192c3e71046c85399c6bb4087595fbc285e5b8ca82a97ee5516ba3f

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