Skip to main content

Symbol-aware snippet references for zensical and pymdownx.snippets

Project description

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

Project details


Download files

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

Source Distribution

zensical_code_references-0.1.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

zensical_code_references-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file zensical_code_references-0.1.0.tar.gz.

File metadata

  • Download URL: zensical_code_references-0.1.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for zensical_code_references-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f1946d65aa90ae392605574cc0be8089459c71f043084bae49226385ab40c39a
MD5 9fb0b063acc5bf95f8c7bafc95a5f1b8
BLAKE2b-256 91ba773d5223e9613c510c9413c5a3fd5f8f227c8208d42549997fd2d93510e9

See more details on using hashes here.

File details

Details for the file zensical_code_references-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: zensical_code_references-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for zensical_code_references-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 248f7a9806679c0f4734464c1615119f9cdfcc15499d4cef632af3e09a6ea583
MD5 942752373e7f2083e6e4f74dd5a68489
BLAKE2b-256 cbd422f7f8e20a792f9b2714ad7cfde7cd2c0876dbb71d7fd942a8cb28b2695b

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