19

I have this code:

%p
   A debtor with the court's approval can hire attorneys via
   %a{:id=>"proc",:href=>'/codes#rule327'}Section 327.

That renders:

A debtor with the court's approval can hire attorneys via Section 327.

I know this is extremely picky, but I do not want the period bolded. When I try:

%p
   A debtor with the court's approval can hire attorneys via
   %a{:id=>"proc",:href=>'/codes#rule327'}Section 327
   \.

It yields:

A debtor with the court's approval can hire attorneys via Section 327 .

I would like to know how do I get:

A debtor with the court's approval can hire attorneys via Section 327.

shicholas
  • 6,123
  • 3
  • 27
  • 38

2 Answers2

39

HAML has helper methods specifically designed to "manipulate whitespace in a more precise fashion than what the whitespace removal methods allow."

There are three methods: surround, precede, and succeed, which provide better whitespace control. In your case, you can use the succeed helper like this to append the period after the link:

%p
  A debtor with the court's approval can hire attorneys via
  = succeed "." do
    %a{:id=>"proc",:href=>'/codes#rule327'}Section 327

See the HAML documentation under "Helper Methods".

mayatron
  • 1,682
  • 2
  • 15
  • 17
  • 2
    Also read: [Haml: Control whitespace around text](http://stackoverflow.com/questions/1311428/haml-control-whitespace-around-text) – mayatron Jul 16 '13 at 17:54
  • This is the better answer. – Kees Briggs Aug 16 '17 at 22:19
  • 1
    Important to note that the tag content ("Section 327") is on the same line as the tag definition. If it is nested on the following line, there will be the space. – Sean M Jan 19 '21 at 15:38
14

You can use the outer "space eater" (>) after the tag definition:

%p
  A debtor with the court's approval can hire attorneys via
  %a{:id=>"proc",:href=>'/codes#rule327'}>Section 327
  .

Manual reference

ualinker
  • 745
  • 4
  • 15
  • 2
    sweet, didn't know that thanks! also for anyone else reading i made a slight edit, there needs to be a backspace in front of the period, otherwise the haml compiler will think thats a class definition. – shicholas Dec 15 '12 at 22:24
  • Other note: mthaml PHP library allows the dot pass. – ualinker Dec 15 '12 at 22:29
  • 9
    @shicholas Note that this also removes space _before_ the tag as well, so this still isn’t exactly what you want. See what the [Haml FAQ has to say about this](http://haml.info/docs/yardoc/file.FAQ.html#q-punctuation). – matt Dec 15 '12 at 23:08
  • @shicholas I'm having the same problem, but inserting a backspace causes the compiler to complain about indentation. Thoughts? – Sam Selikoff Jun 16 '14 at 20:07
  • I'm not sure what you mean by "inserting a backspace" can you please elaborate? – shicholas Jun 16 '14 at 20:29