Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YAML comments in multi-line strings

Tags:

yaml

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 
like image 572
simonzack Avatar asked Jan 02 '14 19:01

simonzack


People also ask

Does YAML support multiline comment?

YAML does not support block or multi-line comments.

Can you put comments in YAML?

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.

How do you mass comment YAML?

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.


1 Answers

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...

like image 71
Iguananaut Avatar answered Sep 30 '22 08:09

Iguananaut