Inline Tags?

334 views
Skip to first unread message

Chris Abad

unread,
Jan 23, 2007, 6:27:47 PM1/23/07
to Haml
Is there any shortcut for using common inline tags such as <a>, <b>,
<strong>, or <em>? I'm looking for something that does not require me
to start a new line. Right now it seems like my only option is to use
the actual HTML code.

Nathan Weizenbaum

unread,
Jan 23, 2007, 8:35:46 PM1/23/07
to ha...@googlegroups.com
No, there isn't. The subject has been brought up in the past, but there
are several issues with allowing inline tags. First, it means that every
line of text has to be parsed to look for them, which would more than
likely take too much time. Second, cause problems with accidentally
parsing text that people didn't want to turn into tags.

Because HTML is whitespace-independent, though, this shouldn't be too
much of a problem. If you need there to be no whitespace, you can use
the precede, succeed, and surround helpers:

= precede ':' do
%strong foo
= succeed '!' do
%em bar
= surround '(', ')' do
%a{ :href => 'http://haml.hamptoncatlin.com } Haml

makes

:<strong>foo</strong>
<em>bar</em>!
(<a href='http://haml.hamptoncatlin.com'>Haml</a>)

- Nathan

Chris Abad

unread,
Jan 23, 2007, 10:17:19 PM1/23/07
to ha...@googlegroups.com
Aren't most of the template languages out there currently parsing each line of text looking for tags? Is it different w/ HAML since the whitespace is active? This is the first "active whitespace" language I've dealt with.

As far as "accidentally parsing text," I think that's more of a matter of using an obvious syntax that would minimize this sort of issue. Worse case scenario, whatever syntax you use can also be escaped if you don't want it to be rendered. I was hoping even something as simple as this would work:

%strong(strong text), followed by regular text

but alas, no dice.

Even something like this could be handy:
= textilize do
This is some *strong* text, and this is some _emphasized_ text.

to render:

<p>
This is some <strong>strong</strong> text, and this is some <em>emphasized</em> text.
</p>

Nathan Weizenbaum

unread,
Jan 23, 2007, 11:03:24 PM1/23/07
to ha...@googlegroups.com
Past the tags at the beginning of the line (the "=" or "%a{ :href =>
'http://haml.hamptoncatlin.com/' }=" or whatever), Haml does no parsing,
at least for most commands; it just passes the line to be output to the
renderer. If we had an inline syntax, we'd have to run a regexp over it
or something, and that takes a significant amount of time.

As to your idea of "textilize", that's actually already implemented in
v1.4 (what will be released as 1.5) as filters. Both textile and
markdown are available by default, as long as you have RedCloth and/or
BlueCloth installed. The syntax is

:textile


This is some *strong* text, and this is some _emphasized_ text.

This minimizes the need for specific syntax to define style, which is
also advantageous because Haml is really designed to emphasize the
structure of a document, rather than the presentation.

- Nathan

Chris Abad

unread,
Jan 23, 2007, 11:11:19 PM1/23/07
to ha...@googlegroups.com
Excellent. I think the filter is going to accomplish what I'm looking for. Is it pretty safe to run off trunk? Do you have a changelog somewhere of the new features sitting in trunk right now?

Nathan Weizenbaum

unread,
Jan 23, 2007, 11:30:30 PM1/23/07
to ha...@googlegroups.com
Yeah, trunk is reasonably safe. Haml is not particularly unstable
software. You could check out the actual changelog
(http://haml.hamptoncatlin.com/svn/repository/changesets) but there'll
be a lot of stuff that you probably don't care about. The new features
in trunk at the moment, though, are pretty much Sass and filters. There
are a few other minor improvements, but those are the most important ones.

- Nathan

Reply all
Reply to author
Forward
0 new messages