# YAML/RedCloth Question

**URL:** <https://rubytalk.org/t/yaml-redcloth-question/16633>\
**Category:** ruby-talk\
**Created:** [20 February 2005 17:59 UTC](https://rubytalk.org/t/yaml-redcloth-question/16633 "2005-02-20T17:59:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Leonard](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Michael\_Leonard](https://rubytalk.org/u/Michael_Leonard)\
**Post date:** [20 February 2005 17:59 UTC](https://rubytalk.org/t/yaml-redcloth-question/16633/1 "2005-02-20T17:59:42Z")

</div>

Hello all,

I'm very new to Ruby, so appy-polly-loggies in advance if the answer to  
this is obvious.

I have a file, qbf.yml, the contents of which are:

----------------qbf.yml----------------  
title: "on dogs and foxes"  
author: "q.b. foks, esq."  
text: "the quick brown

fox jumps

over

the lazy dog"

> **···**
>
> ---------------------------------------
> 
> I want to import it into a Ruby hash and use RedCloth to convert the  
> "text" portion to html. The code I'm using is this:
> 
> ----------------qbf.rb----------------  
> require 'yaml'  
> require 'redcloth'
> 
> qbf=YAML::load(File.open('qbf.yml'))
> 
> puts RedCloth.new(qbf["text"]).to\_html  
> --------------------------------------
> 
> The output I get from this is:
> 
> \<p\>the quick brown  
> fox jumps  
> over  
> the lazy dog\</p\>
> 
> Whereas, I would like:
> 
> \<p\>the quick brown\</p\>  
> \<p\>fox jumps\</p\>  
> \<p\>over\</p\>  
> \<p\>the lazy dog\</p\>
> 
> It looks like when I import the YAML, my paragraph breaks get eaten up.  
> I'd like to avoid this if at all possible. I'm sure the solution is  
> very simple, but I can't seem to get my head around it. Any help would  
> be greatly appreciated.
> 
> Thanks in advance,
> 
> Mike Leonard

---

<div class="post-metadata">

**Author:** ![Jamis\_Buck3](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@Jamis\_Buck3](https://rubytalk.org/u/Jamis_Buck3)\
**Post date:** [20 February 2005 18:25 UTC](https://rubytalk.org/t/yaml-redcloth-question/16633/2 "2005-02-20T18:25:16Z")

</div>

Use triple line breaks to indicate paragraph breaks. It's just the way  
YAML works:

1) A single newline gets eaten (resulting in one long line with no  
&nbsp;&nbsp;&nbsp;newlines)

2) Two newlines get collapsed to one newline

3) Three newlines give you the expected blank line between paragraphs

Also, a syntax like this might read a little easier in your yaml file:

&nbsp;&nbsp;&nbsp;title: on dogs and foxes  
&nbsp;&nbsp;&nbsp;author: q.b. foks, esq.  
&nbsp;&nbsp;&nbsp;text: \>-  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the quick brown  
&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fox jumps  
&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;over  
&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the lazy dog

(Notice the quotes are almost always optional, except when there is  
some question as to what format the data should be. Also, the \>- after  
text: says to eat all following lines wih a greater indentation level  
and treat them as a single text value.)

Hope that helps,

Jamis

> **···**
>
> On 02:59 Mon 21 Feb , mikeleonard wrote:
> 
> > Hello all,
> > 
> > I'm very new to Ruby, so appy-polly-loggies in advance if the answer to  
> > this is obvious.
> > 
> > I have a file, qbf.yml, the contents of which are:
> > 
> > ----------------qbf.yml----------------  
> > title: "on dogs and foxes"  
> > author: "q.b. foks, esq."  
> > text: "the quick brown
> > 
> > fox jumps
> > 
> > over
> > 
> > the lazy dog"  
> > ---------------------------------------
> > 
> > I want to import it into a Ruby hash and use RedCloth to convert the  
> > "text" portion to html. The code I'm using is this:
> > 
> > ----------------qbf.rb----------------  
> > require 'yaml'  
> > require 'redcloth'
> > 
> > qbf=YAML::load(File.open('qbf.yml'))
> > 
> > puts RedCloth.new(qbf["text"]).to\_html  
> > --------------------------------------
> > 
> > The output I get from this is:
> > 
> > \<p\>the quick brown  
> > fox jumps  
> > over  
> > the lazy dog\</p\>
> > 
> > Whereas, I would like:
> > 
> > \<p\>the quick brown\</p\>  
> > \<p\>fox jumps\</p\>  
> > \<p\>over\</p\>  
> > \<p\>the lazy dog\</p\>
> > 
> > It looks like when I import the YAML, my paragraph breaks get eaten up.  
> > I'd like to avoid this if at all possible. I'm sure the solution is  
> > very simple, but I can't seem to get my head around it. Any help would  
> > be greatly appreciated.
> 
> --  
> Jamis Buck  
> jamis\_buck@byu.edu  
> [http://jamis.jamisbuck.org](http://jamis.jamisbuck.org)  
> ------------------------------  
> "I am Victor of Borge. You will be assimil-nine-ed."

---

<div class="post-metadata">

**Author:** ![why\_the\_lucky\_stiff1](https://avatars.discourse-cdn.com/v4/letter/w/898d66/32.png) [@why\_the\_lucky\_stiff1](https://rubytalk.org/u/why_the_lucky_stiff1)\
**Post date:** [20 February 2005 23:19 UTC](https://rubytalk.org/t/yaml-redcloth-question/16633/3 "2005-02-20T23:19:30Z")

</div>

Jamis Buck wrote:

> Use triple line breaks to indicate paragraph breaks. It's just the way
> 
> YAML works:

Unless you use a literal block.

----------------qbf.yml----------------  
title: "on dogs and foxes"  
author: "q.b. foks, esq."  
text: |  
&nbsp;&nbsp;the quick brown

&nbsp;&nbsp;fox jumps

&nbsp;&nbsp;over

&nbsp;&nbsp;the lazy dog

> **···**
>
> ---------------------------------------
> 
> Double-quoted multiline strings act like folded blocks (the rules Jamis described).
> 
> See 'Blocks' in the YAML Cookbook. \<[http://yaml4r.sourceforge.net/cookbook/#blocks&gt](http://yaml4r.sourceforge.net/cookbook/#blocks&gt);
> 
> \_why

---

<div class="post-metadata">

**Author:** ![Jamis\_Buck3](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@Jamis\_Buck3](https://rubytalk.org/u/Jamis_Buck3)\
**Post date:** [20 February 2005 23:39 UTC](https://rubytalk.org/t/yaml-redcloth-question/16633/4 "2005-02-20T23:39:36Z")

</div>

Gah! Now \*that's\* something I wish I'd known six months ago. Would  
have made it much less painful to do the Needle/Net::SSH/etc.  
documentation in YAML.

Thanks for the tip, \_why.

- Jamis

> **···**
>
> On 08:19 Mon 21 Feb , why the lucky stiff wrote:
> 
> > Jamis Buck wrote:
> > 
> > \>Use triple line breaks to indicate paragraph breaks. It's just the way  
> > \>  
> > \>YAML works:  
> > \>  
> > \>  
> > Unless you use a literal block.
> > 
> > ----------------qbf.yml----------------  
> > title: "on dogs and foxes"  
> > author: "q.b. foks, esq."  
> > text: |  
> > the quick brown
> > 
> > fox jumps
> > 
> > over
> > 
> > the lazy dog  
> > ---------------------------------------
> > 
> > Double-quoted multiline strings act like folded blocks (the rules Jamis  
> > described).
> > 
> > See 'Blocks' in the YAML Cookbook.  
> > \<[http://yaml4r.sourceforge.net/cookbook/#blocks&gt](http://yaml4r.sourceforge.net/cookbook/#blocks&gt);
> 
> --  
> Jamis Buck  
> jamis\_buck@byu.edu  
> [http://jamis.jamisbuck.org](http://jamis.jamisbuck.org)  
> ------------------------------  
> "I am Victor of Borge. You will be assimil-nine-ed."
