Does YAML support comments in multi-line strings?
I'm trying to do things like this, but the validator is throwing errors:
key: #comment value #comment value value #comments here don't work either
YAML does not support block or multi-line comments.
In order to add comments to a YAML file, you simply have to use the # (hashtag symbol) at the start of the line. For example, below is an example of one commented line in a YAML file.
The Normal Way for commenting in YAML is Inline commenting with the “#” symbol, however, if you want to comment blocks then we have a list of ways in which it can be done. Step 2: Press cmd plus / on Mac or press ctrl plus / on Linux & Windows.
No. Per the YAML 1.2 spec "Comments must not appear inside scalars". Which is exactly the case here. There's no way in YAML to escape the octothorpe symbol (#
) so within a multi-line string there's no way to disambiguate the comment from the raw string value.
You can however interleave comments within a collection. For example, if you really needed to, you could break your string into a sequence of strings one per line:
key: #comment - value line 1 #comment - value line 2 #comment - value line 3
Should work...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With