Skip to content
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

Add context info and callback to getAttributes #50

Merged
merged 7 commits into from
Jun 28, 2022

Conversation

chriskirknielsen
Copy link
Contributor

Allows to pull in contextual information for the syntax highlighting, and pass it to a defined function to get a dynamic output.

Allows to pull in laguange dynamically
if (typeof value === "function") { // Callback must return a string or a number
value = value(context); // Run the provided callback and store the result
}

if (typeof value !== "string" && typeof value !== "number")
throw new Error(
`Attribute "${key}" must have a value of type string or number not "${typeof value}".`
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea of adding support for callbacks with context. I think we should update the wording of the error message to reflect the allowance of callbacks by saying "…must have, or evaluate to, a value of…"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense! Updating to the following:

`Attribute "${key}" must have, or evaluate to, a value of type string or number, not "${typeof value}".`

@zachleat zachleat merged commit a8ebb01 into 11ty:master Jun 28, 2022
@zachleat
Copy link
Member

We are absolutely going for it here—appreciate this one, I love it!

This will be packaged with 4.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants