Skip to content

[snippet_var_resolver] Add plugin to resolve variables inside of snippets#36

Merged
eshaben merged 7 commits intomainfrom
eshaben/snippet-variables
Apr 2, 2026
Merged

[snippet_var_resolver] Add plugin to resolve variables inside of snippets#36
eshaben merged 7 commits intomainfrom
eshaben/snippet-variables

Conversation

@eshaben
Copy link
Copy Markdown
Collaborator

@eshaben eshaben commented Apr 1, 2026

This pull request introduces a new MkDocs plugin, snippet_var_resolver, which resolves {{ variable }} placeholders in HTML content that remain after snippet injection, ensuring variables from YAML files are correctly rendered even when injected via pymdownx.snippets. The plugin is fully documented, registered in the project, and covered by comprehensive tests.

New Plugin: Snippet Variable Resolver

  • Added SnippetVarResolverPlugin in plugins/snippet_var_resolver/plugin.py, which:
    • Loads variables from YAML files specified in the macros plugin's include_yaml config.
    • Replaces unresolved {{ variable }} placeholders in the HTML after snippet injection, supporting dotted paths and leaving unknown variables untouched.
    • Handles multiple YAML files, merging variables with "last file wins" precedence, and logs helpful debug/warning messages.

Documentation

  • Created docs/snippet-var-resolver.md with usage instructions, configuration details, and notes about plugin behavior and limitations.

Project Registration

  • Registered the plugin entry point in pyproject.toml under [project.entry-points."mkdocs.plugins"].
  • Bumped the project version to 0.1.0a11 to reflect the new feature.

Testing

  • Added tests/snippet_var_resolver/test_snippet_var_resolver.py with thorough unit tests for variable resolution logic, YAML loading, and integration scenarios.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new MkDocs plugin (snippet_var_resolver) to resolve leftover {{ variable }} placeholders in rendered HTML (after snippet injection), using variables sourced from mkdocs-macros-plugin’s include_yaml configuration.

Changes:

  • Introduce SnippetVarResolverPlugin with YAML variable loading + placeholder replacement in on_page_content.
  • Register the new plugin entry point and bump package version to 0.1.0a11.
  • Add dedicated documentation and a new test suite for the resolver behavior.

Reviewed changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
plugins/snippet_var_resolver/plugin.py Implements YAML loading from macros.include_yaml and regex-based placeholder substitution on page HTML.
pyproject.toml Registers the plugin entry point and bumps the project version.
docs/snippet-var-resolver.md Documents the motivation, usage, and behavior/limitations of the plugin.
tests/snippet_var_resolver/test_snippet_var_resolver.py Adds unit tests for dotted-path lookup, substitution behavior, and YAML include loading/merging.
plugins/snippet_var_resolver/__init__.py Package marker for the new plugin module.
tests/snippet_var_resolver/__init__.py Package marker for the new test module.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/snippet_var_resolver/plugin.py Outdated
Comment thread plugins/snippet_var_resolver/plugin.py Outdated
Comment thread tests/snippet_var_resolver/test_snippet_var_resolver.py
Comment thread tests/snippet_var_resolver/test_snippet_var_resolver.py Outdated
Comment thread tests/snippet_var_resolver/test_snippet_var_resolver.py
@eshaben eshaben requested a review from 0xlukem April 1, 2026 03:58
@0xlukem 0xlukem self-assigned this Apr 1, 2026
Copy link
Copy Markdown
Contributor

@0xlukem 0xlukem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

@eshaben eshaben merged commit f4f6373 into main Apr 2, 2026
@eshaben eshaben mentioned this pull request Apr 9, 2026
5 tasks
@eshaben eshaben changed the title Add plugin to resolve variables inside of snippets [snippet_var_resolver] Add plugin to resolve variables inside of snippets Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants