Reputation: 4289
I am new to YAML, and have tried to do a YAML block but I am getting the following error:
while scanning a block mapping: expected , but found: #< ScalarToken Value="content: | This is a test of a test test test test A very very good test yeah yeah A test of test test" Style="None"> (line 8, column 1)
While it works fine without the |, I want whitespace preservation.
YAML file (Home.yml):
---
section:
title: About this site
content: |
This is a test of a test test test test
A very very good test
A test of test test
section:
title: Source code
content: |
Licens:: BSD
Link:: Here
Foo
...
Ruby code:
home = YAML.load_file('data/Home.yml')
home.inspect
Upvotes: 3
Views: 4911
Reputation: 107999
Which YAML parser are you using? Both the Ruby 1.8.7 parser and the parser in 1.9 parse the YAML in your question.
There's still trouble, through. The syntax you've given is for a hash like this:
{
'section' => {
'title' => "About this site",
'content => ...
}
'section' => {
'title' => 'Source code',
'content' => ...
}
}
However, you can't have two hash keys be the same. What happens is that the last one wins. You may be looking for an array of hashes. To do that, use this YAML syntax:
---
-
section:
title: About this site
content: |
This is a test of a test test test test
A very very good test
A test of test test
-
section:
title: Source code
content: |
Licens:: BSD
Link:: Here
Foo
Upvotes: 1