2
votes

I am using haml, I have some strong text but after that text is continued, but haml adds an space between the strong text and non strong text. Is there a way to remove it, or proper way to write this sentence.

%strong
  Unmet
, indicating your requirements are not satisfied.

This generates

Unmet , indicating your requirements are not satisfied.

There is a space between 'Unmet' and ','

How can I remove that space?

One solution I have read is to use an haml helper but that seems excessive for this little thing.

Also what about if I need space in the beginning but not at the end of the strong tag.

This is
%strong
  Unmet
, indicating your requirements are not satisfied.

I would like the outcome to be like

This is Unmet, indicating your requirements are not satisfied.
2

2 Answers

2
votes

Haml isn’t very goos at things like this. From the FAQ:

Expressing the structure of a document and expressing inline formatting are two very different problems. Haml is mostly designed for structure, so the best way to deal with formatting is to leave it to other languages that are designed for it.

The simplest way to do this would be just to include the HTML inline:

This is <strong>Unmet</strong>, indicating your requirements are not satisfied.

Another way would be to use a different language as the FAQ suggests, through a filter such as markdown:

:markdown
  This is **Unmet**, indicating your requirements are not satisfied.

Note that you can use interpolation (#{...}) inside a filter if you need dynamic content.

1
votes

According to the docs, > and < give you more control over the whitespace near a tag. > will remove all whitespace surrounding a tag, while < will remove all whitespace immediately within a tag.

%strong<>
  Unmet
, indicating your requirements are not satisfied.

produces

Unmet, indicating your requirements are not satisfied.

EDIT:

If you want to add a whitespace before a tag (without a HAML helper function) then I think the easiest option is to include &nbsp; where you want the single space.

I know this guy&nbsp;
%strong<>
  John
, he is very nice

produces

I know this guy John, he is very nice