Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape hash (#) character in a multi-line string in yaml?

Tags:

markdown

yaml

I need to do something like the following:

description: |-
    #This is not a comment#
    Some more text.

But of course the first line is interpreted as a comment by the yaml parser. I cannot use double quotes here since I need this to be multiline.

What can I do to achieve this?

Thanks.

like image 921
Alejandro Zuleta Avatar asked Oct 03 '22 01:10

Alejandro Zuleta


1 Answers

It should work the way you have it if you really have it indented properly which it seems that you do. So maybe it is a bug in your parser.

It seems to work with SnakeYAML - copy pasting your snippet to http://instantyaml.appspot.com/ returns:

%YAML 1.1
---
!!map {
    ? !!str "description"
    : !!str "#This is not a comment#\nSome more text.",
}
...

Which is essentially the same as when you try the same example without hashes:

%YAML 1.1
---
!!map {
    ? !!str "description"
    : !!str "This is not a comment\nSome more text.",
}
...
like image 62
Jakub Kotowski Avatar answered Oct 21 '22 08:10

Jakub Kotowski