-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for custom YAML tags #489
Comments
Although a custom constructor is a more general solution -- and I like the generality in principle -- if If you really need customizations for the YAML parsing, I think the interface needs some serious thought. One solution I like would be to allow users to pass their own parser. Then you can do whatever you want with no limitations, but I only want to pursue more complex solutions if there's sufficient demand. I think we can meet your needs with "ignore unknown tags" as an option, so I'll look into that first. |
I just discovered this tool via another tool that uses the pre-commit hook provided. I have so far only used the vscode extension We use mkdocs-material which provides its own schema on top of that of [...]
plugins:
- git-revision-date-localized:
# only enable when building in CI to speed up local builds
# https://squidfunk.github.io/mkdocs-material/setup/adding-a-git-repository/#+git-revision-date-localized.enabled
enabled: !ENV [CI, false]
[...]
markdown_extensions:
- pymdownx.superfences:
custom_fences:
- name: mermaid
class: mermaid
format: !!python/name:pymdownx.superfences.fence_code_format Both values of Several files failed to parse.
FailedFileLoadError: Failed to parse mkdocs.yml
in "<path>/docs/.venv/lib/python3.13/site-packages/check_jsonschema/instance_loader.py", line 48
>>> data: t.Any = self._parsers.parse_data_with_path(
caused by
ConstructorError: could not determine a constructor for the tag '!ENV'
in "<byte string>", line 94, column 16:
enabled: !ENV [CI, false]
^ (line: 94)
in "<path>/docs/.venv/lib/python3.13/site-packages/check_jsonschema/parsers/__init__.py", line 93
>>> return loadfunc(data) The vscode extension allows to define custom tags: "yaml.customTags": [
"!ENV scalar",
"!ENV sequence",
"!relative scalar",
"tag:yaml.org,2002:python/name:material.extensions.emoji.to_svg",
"tag:yaml.org,2002:python/name:material.extensions.emoji.twemoji",
"tag:yaml.org,2002:python/name:pymdownx.superfences.fence_code_format"
] This is documented here: https://squidfunk.github.io/mkdocs-material/creating-your-site/?h=yaml#minimal-configuration In the built-in pre-commit hook (which also uses |
This issue requested support specifically for the
!reference
tag in a Gitlab CI file, however, there doesn't appear to be support for other tags. Specifically in my case, Ansible-specific tags like!unsafe
or!vault
.Example content:
Output:
The workaround in my case is to convert the content to JSON with
yq
then validate--which isn't ideal.Is it possible to add support for custom tags like these? Possibly by allowing the user to pass in a custom constructor for their respective tags that can be passed through to the
ruamel.yaml
parser.The text was updated successfully, but these errors were encountered: