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
prosemirror: ProseMirror JSONquill: Quill.js Delta JSON (Soon)slate: Slate.js JSON (Soon)
API
convert(data: dict, fmt: str | BaseParser) -> str
data: The rich text JSON objectfmt: 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 packageconverter.py— Format dispatch and APIbase.py— Parser interfaceexceptions.py— Error typesformats/— Built-in format parsers (Quill, Slate, ProseMirror)
tests/— Unit and robustness tests
License
MIT License. See LICENSE.
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
richtext_typst-0.1.0.tar.gz
(4.0 kB
view details)
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
183874221887f159c38b3126d9f653aad2f7034b1bc3f999ad4e1b88404129cc
|
|
| MD5 |
594c3343d0b93cef69d9c1f7ea60d7a1
|
|
| BLAKE2b-256 |
bbc47694477fec8ed3318e90ce46f53701d2d9bfca767e74e4cd8c53beb10b30
|
File details
Details for the file richtext_typst-0.1.0-py3-none-any.whl.
File metadata
- Download URL: richtext_typst-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc197b5b34f98052f7ef1ea92e82d53380ddf0f802fcbcbe2fb052fd2a3975fe
|
|
| MD5 |
feec2b2610a449f4f6fa61788e10c662
|
|
| BLAKE2b-256 |
4ca5b99c5e5bc395293968e71513b60c84e2d719ae7c268d3162d8e5ebe02482
|