Skip to main content

djot-py

A Python library for parsing the light markup format djot.

This implementation is based on and modified from djot.js.

Usage

pip install djot-py

API

To parse text into an AST, call parse:

from djot import parse

ast = parse("hi there\nfriend\n\nnew para")

To parse text into events:

from djot import EventParser

text = "hello *world*\n\nfoo"

parser = EventParser(text)

# The parse method returns an iterator of events.
for event in parser.parse():
    print(event)

There are no rendering features available currently. Will be added in the future.

Differences from Djot.js

  • Comment is not supported yet.
  • Multi-line attributes is not supported yet.

My personal view on the above not-yet-implemented features

Comment

Comment should not be mixed with attributes.

I hope there's a specific comment syntax in the future. For example, there could be two types of comments:

  • Line comment appeared at the end of each line, using symbols like %%
  • Block comment wrapped in %%%, similar to code block.

Multi-line attributes

Djot.js current implementation to support multi-line attributes involves a lot of backtracing, which is in direct conflict with the philosophy of djot. To support multi-line attributes, there needs a fundamental change in the line-based parsing algorithm.

List

This is not hard to implement. However, too much choices might introduce future ambiguity. I prefere simplicity rather than feature-rich. For example, Typst style simply uses - and +. Leave styling to a renderer. And block attributes could be used to convey some basic styling information.

Metadata

Release files for djot-py 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for djot-py 0.1.0
File Size Uploaded
djot_py-0.1.0.tar.gz 68.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for djot-py 0.1.0
File Interpreter ABI Platform
djot_py-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 168.5 kB

Release files / djot_py-0.1.0.tar.gz

Download URL djot_py-0.1.0.tar.gz
Size 68.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c5c74511fbbcd37aab633de65864e7d1ded56148d50212eb092dcb77c05ed505
BLAKE2b-256 checksum
How to use checksums
d686c73b21ace67e609dcf3dbd92a835295b7a991a98b5fd96f76a7511d46966
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / djot_py-0.1.0-py3-none-any.whl

Download URL djot_py-0.1.0-py3-none-any.whl
Size 100.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
047f9140d79f20664eab1b5f8f1f60a32c902983e12589ebde84b1d4ff0fafb6
BLAKE2b-256 checksum
How to use checksums
7f7c4f7a0f336f374c719d7fa0207693a0409bc4dd967803c6d3b5bf7c25ce59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page