Skip to main content

djot-fmt

Automatic formatter for djot markup files.

Overview

djot-fmt is a command-line tool that automatically formats djot files, focusing primarily on fixing common list formatting issues:

  • Missing newlines between list items
  • Incorrect indentation for nested lists
  • Blank line spacing before nested content

Installation

go install github.com/KyleKing/djot-fmt@latest

Or from PyPI, which ships the same formatter as a shared library bound with ctypes:

uv tool install djot-fmt   # or: pipx install djot-fmt
uvx djot-fmt file.dj       # run without installing

The Python wheels carry a compiled library rather than a reimplementation, so output is byte-identical to the Go binary. Formatting runs in-process, which costs about 9 microseconds for a small document against roughly 3 milliseconds to spawn the CLI.

Python API

import djot_fmt

djot_fmt.format('-  a\n-  b\n')  # '- a\n- b\n'
djot_fmt.format(source, wrap_sentences=False)

format raises djot_fmt.DjotFormatError on input the formatter rejects. Calls are serialized internally because the underlying djot parser is not goroutine-safe.

The shared library is opened on the first call rather than at import, so a process that imports djot_fmt and then forks stays safe. Calling into it before forking does not, because the Go runtime does not survive fork() without exec(). Use the spawn or forkserver start method with multiprocessing.

Usage

Basic Usage

# Format stdin to stdout
cat file.dj | djot-fmt

# Format file and write back
djot-fmt -w file.dj

# Format multiple files and write back
djot-fmt -w file1.dj file2.dj file3.dj

# Check if file is formatted (exit 1 if not)
djot-fmt -c file.dj

# Check multiple files
djot-fmt -c file1.dj file2.dj file3.dj

# Format to different file
djot-fmt -o output.dj input.dj

Batch Processing

# Format all .dj files in current directory
fd -e dj -x djot-fmt -w

# Format all .dj files in specific directory
fd -e dj . content/ -x djot-fmt -w

# Check formatting for all .dj files
fd -e dj -x djot-fmt -c

# Using find (alternative to fd)
find . -name "*.dj" -exec djot-fmt -w {} \;

Options

  • -w, --write - Write result to source file(s) instead of stdout
  • -c, --check - Check if file(s) are formatted (exit 1 if not)
  • -o, --output FILE - Write output to FILE instead of stdout (single input file only)
  • -h, --help - Show help message
  • -v, --version - Show version information

SLW (Semantic Line Wrap) Options

  • --no-wrap-sentences - Disable semantic line wrapping
  • --slw-markers TEXT - Characters that mark sentence endings (default: ".!?")
  • --slw-wrap INTEGER - Maximum line width for wrapping (default: 88, set to 0 to disable)
  • --slw-min-line INTEGER - Minimum line length before wrapping (default: 40, set to 0 for aggressive mode)

Development

This project uses mise for tool management and hk for git hooks.

Setup

# Install mise (if not already installed)
# See: https://mise.jdx.dev/getting-started.html

# Install project tools
mise install

# Install git hooks
hk install --mise

Common Commands

# Run all checks (linting, tests)
mise run ci

# Format code
mise run fmt

# Run tests
mise run test

# Build binary
mise run build

# Install locally
mise run install

Python bindings

# Build the wheel (compiles bindings/cshared with -buildmode=c-shared)
uv build --wheel

# Run the Python tests against the built wheel
uv run --isolated --with dist/*.whl --with pytest pytest bindings/python/tests

bindings/cshared/lib.go is the cgo boundary. Every exported function there recovers from panics, because a panic crossing into C terminates the host process, which for a Python caller means killing the interpreter. Strings allocated on the Go side are freed through DjotFree.

Roadmap

Future enhancements under consideration:

  • Support for all djot node types (ordered lists, tables, code blocks, etc.)
  • Configurable formatting options (indentation width, line wrapping)
  • Semantic line wrapping (similar to mdformat-slw)
  • Code block formatting integration

License

MIT

Credits

Built using godjot for djot parsing and AST manipulation.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djot_fmt-0.1.2.tar.gz (23.3 kB view details)

Uploaded Source

Built Distributions

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

djot_fmt-0.1.2-py3-none-win_arm64.whl (769.6 kB view details)

Uploaded Python 3Windows ARM64

djot_fmt-0.1.2-py3-none-win_amd64.whl (843.9 kB view details)

Uploaded Python 3Windows x86-64

djot_fmt-0.1.2-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (785.4 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

djot_fmt-0.1.2-py3-none-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (848.7 kB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

djot_fmt-0.1.2-py3-none-macosx_15_0_x86_64.whl (846.8 kB view details)

Uploaded Python 3macOS 15.0+ x86-64

djot_fmt-0.1.2-py3-none-macosx_15_0_arm64.whl (797.9 kB view details)

Uploaded Python 3macOS 15.0+ ARM64

File details

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

File metadata

  • Download URL: djot_fmt-0.1.2.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for djot_fmt-0.1.2.tar.gz
Algorithm Hash digest
SHA256 530f57f354fb63977e1f9e34fdb31a0526131c306cb09e8b5bacd2f0244732f5
MD5 f46cc49ba486741aa2440e7ac5f61b48
BLAKE2b-256 39f02962dedf00468bb2caf1b745742aa7ff34ed0510cfcb01af4e33c6651dd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for djot_fmt-0.1.2.tar.gz:

Publisher: publish.yml on KyleKing/djot-fmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file djot_fmt-0.1.2-py3-none-win_arm64.whl.

File metadata

  • Download URL: djot_fmt-0.1.2-py3-none-win_arm64.whl
  • Upload date:
  • Size: 769.6 kB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for djot_fmt-0.1.2-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 714f29c9f643b1617608ce545854e7207e51e32f663486084fa5d369bb043617
MD5 0b76b9802625570023381043191c41f8
BLAKE2b-256 1acc8155d1a54779bc559d484a3e0fd0edef91ea20351cd4360d068afac9032d

See more details on using hashes here.

Provenance

The following attestation bundles were made for djot_fmt-0.1.2-py3-none-win_arm64.whl:

Publisher: publish.yml on KyleKing/djot-fmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file djot_fmt-0.1.2-py3-none-win_amd64.whl.

File metadata

  • Download URL: djot_fmt-0.1.2-py3-none-win_amd64.whl
  • Upload date:
  • Size: 843.9 kB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for djot_fmt-0.1.2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 692b9fa4cc80476868d1da4e00a3077813eff5e1cbaaaae0501f2a7ff7a4098c
MD5 4bf82d89344a5944144fa5ce335b4259
BLAKE2b-256 587ec50610412921bab603a716147fc7509173fac4812c236c5af19f2512ea65

See more details on using hashes here.

Provenance

The following attestation bundles were made for djot_fmt-0.1.2-py3-none-win_amd64.whl:

Publisher: publish.yml on KyleKing/djot-fmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file djot_fmt-0.1.2-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for djot_fmt-0.1.2-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d927ea050f6b1b94c62d5368a95280fa3d742ecfda5870aeb245ae1e35dc4713
MD5 70e060a2533a2ab02879b3c3f9debec5
BLAKE2b-256 258af583811d5edf98a9681979ddc4733cc21eadafefa5b7d6342361766851f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for djot_fmt-0.1.2-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: publish.yml on KyleKing/djot-fmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file djot_fmt-0.1.2-py3-none-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for djot_fmt-0.1.2-py3-none-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 10a1c05a4afd603b3494b603a78209b75b5b2782361838e01f579eb0e611f7a0
MD5 4e6592af7a5b993f990b7c09de5e22a4
BLAKE2b-256 eb4520775bbcbb6041d71b78abbb9e7057faaf9c84aa70099e2eff68e44622fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for djot_fmt-0.1.2-py3-none-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: publish.yml on KyleKing/djot-fmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file djot_fmt-0.1.2-py3-none-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for djot_fmt-0.1.2-py3-none-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 1af48f6e1714f7c64ddb5fbbcf03be69350f86311d7af7f36908c5ca31ec8378
MD5 0e809d1b12449f8777b22bc0074cc834
BLAKE2b-256 3b10d2c7177735bb981f6529c66b511e2c1ea5f13465462379fe7b48f51b725f

See more details on using hashes here.

Provenance

The following attestation bundles were made for djot_fmt-0.1.2-py3-none-macosx_15_0_x86_64.whl:

Publisher: publish.yml on KyleKing/djot-fmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file djot_fmt-0.1.2-py3-none-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for djot_fmt-0.1.2-py3-none-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 5acd3d30a25bc33dd6edccd0da3a942e0730a62050bd4a64e83fe022cfef24a2
MD5 06a30b88b329f9c7b757eb6096234caf
BLAKE2b-256 9ca976e63b7d8f7e4105d20ac508f2f8e8d9df99ccc1249b7975403d7a3198dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for djot_fmt-0.1.2-py3-none-macosx_15_0_arm64.whl:

Publisher: publish.yml on KyleKing/djot-fmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page