-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
MANUAL: clarify truthiness in template variables #4631
Conversation
There are multiple YAML standards that are slightly inconsistent, but they all do ascribe some type to all values (defaulting to the YAML 1.2 has the concept of schemas. In the Core Schema that extends JSON, a regex for booleans is given as:
YAML 1.1 is more common, and has a tag library in which the bool type is defined as y/n, yes/no, true/false, on/off. Each keyword can be lowercase, uppercase, and capitalized. Neither YAML standard seems to ascribe truthiness to non-booleans such as zero, null, or lists. Those would be application-dependent. So the question is, which YAML standard and schema does Pandoc use by default? And how does Pandoc coerce non-boolean values to booleans? If I read the linked doctemplates source correctly, any JSON value should be truthy that is coerced by |
We currently use this library to parse YAML: |
So, the proposed documentation change is incomplete. Truthy values include not just |
Thanks @latk for the pointer to resolveVar, which is called by cond – so if And thanks to @jgm for pointing out how the YAML parses booleans. I've thusly changed the pull request. But it's now a very long and complicated text. Maybe that should better go in the README for the |
Mauro Bieg <notifications@github.com> writes:
I've thusly changed the pull request. But it's now a very long and complicated text. Maybe that should better go in the README for the `doctemplates` library and we just add a link to it from the MANUAL?
Well, the fact that "y" evaluates as a boolean True is a fact about
YAML, and the doctemplates library has nothing inherently to do with
YAML. The "context" provided to that library is an Aeson structure
that can be produced by parsing YAML, but can also be produced in
various other ways. So I don't think that's the right place to document
this.
|
MANUAL.txt
Outdated
any valid template text, and may include interpolated variables or other | ||
conditionals. The `$else$` section may be omitted. | ||
This will include `X` in the template if `variable` has a truthy | ||
value; otherwise it will include `Y`. (Here a truthy value is: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get rid of the extra layer of parens: (Here
-> Here
.
How about something like this:
Now that this is documented, I see some things we may want |
Okay, we're getting there! Changed the commit again... Not sure it's clear to the reader that an |
It's certainly surprising... but there must have been a special reason to implement it in this (more complicated) way. Maybe it was desirable to have an array containing only one element behave in the same way as that element by itself? |
Thanks! |
closes #2281
I couldn't find the relevant code in https://www.stackage.org/haddock/lts-11.7/doctemplates-0.2.2.1/src/Text.DocTemplates.html
--metadata x=no
is parsed as a YAML booleanfalse
? Is that specific to pandoc or a YAML thing?