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…