HAML using links in text without newline

leifg picture leifg · May 1, 2011 · Viewed 29.5k times · Source

I'm currently developing a little Sinatra Ruby app. For the presentation layer I'm using HAML, which works quite well.

However I have a FAQ page which has longer text paragraphs, which is not a problem. But in some passages I'd like to include links. With pure HTML this is very easy to achieve and is still readable.

<p>
I'm talking about <a href="http://ruby-lang.org">Ruby</a> in this text.
</p>

With HAML I'm stuck with this new paragraphs, which then looks like this:

%p
 I'm talking about 
 %a {:href => 'http://ruby-lang.org'}>Ruby 
 in this text.

I think this really breaks the workflow.

Is there a way in HAML to just insert a link without using a newline?

Answer

Dmitry Polushkin picture Dmitry Polushkin · May 11, 2011

It's easier than you might think. Just read this reference: http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#whitespace_removal__and_

So usage is simple, just add less-sign "<" after your %p tag, e.g.:

%p<
 I'm talking about 
 %a {:href => 'http://ruby-lang.org'}>Ruby 
 in this text.

And it will generate exactly that you want to do.