Skip to content

Instantly share code, notes, and snippets.

@freshtonic
Created April 23, 2010 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save freshtonic/376081 to your computer and use it in GitHub Desktop.
Save freshtonic/376081 to your computer and use it in GitHub Desktop.
%p
Blah blah blah blah
%a(href='#foo') foo
and
%a(href='#bar') bar
\.
-# The problem with the above Haml fragment is that I am left with a space after <a href='#bar'>bar</a> and before the period.
-# Haml's whitespace removal does not resolve the issue, because it can either remove ALL whitespace
-# around an element or ALL whitespace within an element. Neither option seems to fit the bill.
-# AFAIK from reading the docs, you can't put whitespace removal around the text node either.
-# What's the (preferably clean) solution?
%p
Blah blah blah blah
%a(href='#foo') foo
and
<a href='#bar'>bar</a>.
-# works around the issue.
@freshtonic
Copy link
Author

The text node being the period at the end.

Everything would work beautifully if Haml if I could say 'remove white space before/after the node' instead of 'inside/surrounding the node'. And it would be even awesomer if text nodes supported the > and < operators.

@freshtonic
Copy link
Author

%p
Blah blah blah blah
%a(href='#foo') foo
and
bar.

-# the above works around the issue

@auxesis
Copy link

auxesis commented Apr 23, 2010

crazy

@jeremyw
Copy link

jeremyw commented Apr 24, 2010

There are a couple ways to do this. One is to use the succeed helper:

%p
  = succeed '.' do
    Blah blah blah blah
    %a(href='#foo') foo
    and
    %a(href='#bar') bar

The other (which I prefer) is to use another markup syntax for content (as opposed to Haml for document structure). See http://chriseppstein.github.com/blog/2010/02/08/haml-sucks-for-content/. Here's an example using Textile, but you could do something similar with Markdown:

:textile
  Blah blah blah blah "foo":#foo and "bar":#bar.

@auxesis
Copy link

auxesis commented Apr 28, 2010

@jeremyw oh rad, thanks for the heads up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment