Skip to main content

Validate Mermaid diagrams in Markdown files

Project description

nixie

nixie validates Mermaid diagrams embedded in Markdown files.

Features

  • Recursively searches directories for Markdown files while honouring .gitignore
  • Scans the current directory for Markdown files when run without arguments
  • Parses mermaid code blocks and uses @mermaid-js/mermaid-cli to validate
  • Processes diagrams sequentially within each file to guarantee stable, bracketed output
  • Prints clear error messages for failing diagrams

Requirements

  • Python 3.14+
  • Node.js with npx or Bun with bun x --bun and @mermaid-js/mermaid-cli

Installation

From PyPI

End users should install the latest release as a uv tool:

uv tool install nixie-cli

This provides the nixie command without any development extras.

Development Setup

To contribute to nixie, install the package in editable mode and set up development tools using uv, Astral's fast Python package manager:

pip install -e .
uv sync --include dev

Usage

nixie [--verbose] [--no-sandbox] [--mermaid-version VERSION]
      [--max-concurrency N] [FILE ...]

Diagram checks are scheduled concurrently across and within files using a global worker limit. Output remains deterministic: file boundaries and diagram markers are emitted in the order files and diagrams appear in the input. --max-concurrency is clamped to max(1, cpu_count - 1). Paths can be files or directories. If no files are provided, nixie searches the current working directory for Markdown files, excluding paths matched by .gitignore in that directory. Discovery includes files with the .md extension (case-sensitive). Files are processed in the order provided on the command line.

Exit codes

  • 0 — All diagrams in processed files validated successfully.
  • 1 — At least one diagram failed to render or a processing error occurred.

Only the .gitignore file in the working directory is used; nested .gitignore files are ignored.

--verbose sets the nixie.cli logger to INFO, logging the exact mermaid-cli command for each diagram. By default, nixie launches Puppeteer with --disable-setuid-sandbox, --disable-gpu, and --disable-dev-shm-usage for reliable headless operation. Use --no-sandbox to also pass --no-sandbox to Chromium. --mermaid-version selects the @mermaid-js/mermaid-cli version when nixie launches npx or bun. The default is latest, and the flag is ignored when mmdc is found on disk. --max-concurrency bounds the number of simultaneous mermaid-cli processes.

When multiple files are provided, nixie prints markers that show where the output for each file starts and ends. Each Mermaid diagram is also bracketed with its line numbers and schema name. The start marker’s line number is the first content line inside the fenced block; the end marker’s line number is the closing fence line.

Schema detection:

  • The schema is the first token on the first non-blank, non-comment line inside the fenced block. Lines starting with %% are treated as comments.
  • If no such token exists, the schema is reported as UNKNOWN_SCHEMA (rendered as <unknown>).
  • Schema names are echoed verbatim and are case-sensitive.

Example:

==> path/to/file.md
--> line 10: sequenceDiagram
<-- line 20: sequenceDiagram
<== path/to/file.md

Errors reported while rendering a diagram appear between the --> and <-- lines for that diagram. Markers are printed on stdout; messages from mermaid-cli are emitted on stderr. Most terminals interleave these streams by write order, so the error lines will typically appear between the markers.

Example:

$ nixie bad.md
Parse error on line 1:
invalid diagram
^
Unexpected token: syntax error

Development

Run formatting, linting, type checking and tests before committing:

ruff format
ruff check
pyright
pytest

The integration tests mock the CLI so Node.js is not needed during testing.

Project Structure

  • nixie/cli.py – command-line interface and validation logic
  • nixie/unittests/ – unit tests for helper functions
  • tests/integration/ – behavioural tests covering the CLI

License

Licenced under the ISC licence. See LICENSE for license details.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

nixie_cli-1.0.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file nixie_cli-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: nixie_cli-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nixie_cli-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06d2e9d4ee0a0036b49f3b17ba5637b9a46da36859d8f833c7a7f82958ce9455
MD5 5b6b79e0ed40a261b8a28a68159dbbbd
BLAKE2b-256 1bfc79740e79f0e36062ab5e07528f9a82d0881e86343100f50cfc17337766d5

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