YAML comments in multi-line strings

yaml

Solution

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

Problem

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

Original source