Skip to main content

zensical-code-references

PoC extension for Zensical that makes pymdownx.snippets symbol-aware.

Why this exists

Raw line ranges are brittle. If code moves, references like file.py:88:121 rot.

This extension allows snippet references by Python symbol and resolves them to real line spans at build time using AST.

Symbol reference format

<module.path>:<symbol>(.<nested>)[:start[:end]]

Examples:

  • my_pkg.api:build_payload
  • my_pkg.api:Client.send
  • my_pkg.config:DEFAULT_TIMEOUT:-1:2

Resolved output is rewritten to standard snippets format:

path/to/file.py:start:end

Selector behavior

  • No selector: full symbol span.
  • Method references without selectors include class header + method body (not sibling methods like __init__).
  • :start: from relative line start to symbol end.
  • :start:end: relative span from symbol start.
  • Positive values are 1-based (1 is first line of symbol).
  • 0 and negatives are offsets (0 is symbol start, -1 is one line above).

Zensical configuration (zensical.toml)

[project.markdown_extensions.zensical_symbolic_snippets]
module_roots = ["src"]
fail_on_unresolved = true

[project.markdown_extensions.pymdownx.highlight]
anchor_linenums = true
line_spans = "__span"
pygments_lang_class = true

[project.markdown_extensions.pymdownx.snippets]
base_path = ["src"]
check_paths = true

[project.markdown_extensions.pymdownx.superfences]

If you define project.markdown_extensions explicitly, include all extensions you rely on. Leaving out pymdownx.superfences/pymdownx.highlight causes fenced blocks to render as plain text.

Markdown usage stays standard:

--8<-- "my_pkg.api:Client.send"

Included proof project

This repo includes a working Zensical example that references this package's own source to prove behavior:

  • Config: examples/zensical/zensical.toml
  • Docs page: examples/zensical/docs/index.md

Build it:

uv run zensical build --config-file examples/zensical/zensical.toml

Tiny output example (from examples/zensical/site/index.html):

def parse_symbolic_reference(value: str) -> SymbolicReference | None:
    if ":" not in value:
        return None

Tests

Run:

uv run pytest

The suite includes parser/resolver tests plus an E2E Zensical build test that asserts resolved symbols are rendered in generated HTML.

Release automation

GitHub Actions is configured to publish to PyPI on strict semver tags:

  • CI workflow: .github/workflows/ci.yml
  • Release workflow: .github/workflows/release.yml
  • Trigger: push tag matching vX.Y.Z
  • Guardrails: tag must be strict semver and must match project.version in pyproject.toml
  • Gate: test matrix (3.13, 3.14) must pass before publish

One-time GitHub setup for trusted publishing:

  1. Create environment pypi in repository settings.
  2. Configure PyPI Trusted Publisher for this repository/workflow.

Release command:

git tag v0.1.0
git push upstream v0.1.0

Metadata

Release files for zensical-code-references 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 zensical-code-references 0.1.0
File Size Uploaded
zensical_code_references-0.1.0.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for zensical-code-references 0.1.0
File Interpreter ABI Platform
zensical_code_references-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.5 kB

Release files / zensical_code_references-0.1.0.tar.gz

Download URL zensical_code_references-0.1.0.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f1946d65aa90ae392605574cc0be8089459c71f043084bae49226385ab40c39a
BLAKE2b-256 checksum
How to use checksums
91ba773d5223e9613c510c9413c5a3fd5f8f227c8208d42549997fd2d93510e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.05","id":"yarara","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

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

Download URL zensical_code_references-0.1.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
248f7a9806679c0f4734464c1615119f9cdfcc15499d4cef632af3e09a6ea583
BLAKE2b-256 checksum
How to use checksums
cbd422f7f8e20a792f9b2714ad7cfde7cd2c0876dbb71d7fd942a8cb28b2695b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.05","id":"yarara","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

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