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_payloadmy_pkg.api:Client.sendmy_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 linestartto symbol end.:start:end: relative span from symbol start.- Positive values are 1-based (
1is first line of symbol). 0and negatives are offsets (0is symbol start,-1is 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.versioninpyproject.toml - Gate: test matrix (
3.13,3.14) must pass before publish
One-time GitHub setup for trusted publishing:
- Create environment
pypiin repository settings. - Configure PyPI Trusted Publisher for this repository/workflow.
Release command:
git tag v0.1.0
git push upstream v0.1.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1946d65aa90ae392605574cc0be8089459c71f043084bae49226385ab40c39a
|
|
| MD5 |
9fb0b063acc5bf95f8c7bafc95a5f1b8
|
|
| BLAKE2b-256 |
91ba773d5223e9613c510c9413c5a3fd5f8f227c8208d42549997fd2d93510e9
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
248f7a9806679c0f4734464c1615119f9cdfcc15499d4cef632af3e09a6ea583
|
|
| MD5 |
942752373e7f2083e6e4f74dd5a68489
|
|
| BLAKE2b-256 |
cbd422f7f8e20a792f9b2714ad7cfde7cd2c0876dbb71d7fd942a8cb28b2695b
|