MtHaml icon indicating copy to clipboard operation
MtHaml copied to clipboard

whitespace removal syntax not working with php-statements

Open stmh opened this issue 10 years ago • 12 comments

Hi,

the php-renderer does not respect the whitespace-removal-settings of parent-nodes, which will introduce unwanted whitespaces.

Here's an example:

  %a<>
    - foreach(array(1,2,3) as $ndx)
      %span<>
        =$ndx

should render to something like

<a><span>1</span><span>2</span><span>3</span></a>

It looks not that easy to fix the underlying problem, so I replaced all write with raw in my fork. Is there an easy way to fix this?

stmh avatar Mar 25 '14 17:03 stmh

Same thing in Haml/TWIG when using if/for/macros/etc.

White space removal is really useful when using inline or inline-block positioning for horizontal layouts, i.e. this is not just cosmetic. See: http://css-tricks.com/fighting-the-space-between-inline-block-elements/, stmh's issue above is the same thing.

chrisrichard avatar Apr 01 '14 03:04 chrisrichard

Whitespace removal won't work for me at all.

This MtHaml:

    %span.text-small><
      (
      = $no_reviews
      )

produces this HTML:

<span class="text-small">(
    16    )</span>

Please mark this a a bug.

PS Haml docs: http://haml.info/docs/yardoc/file.REFERENCE.html#whitespace_removal__and_

lolmaus avatar Jul 10 '14 16:07 lolmaus

From your example, it works as documented: it removes whitespace just after <span class="text-small">, and just before </span>, but not in the content (which is what it's expected to do).

See the example from HAML/Ruby documentation:

%img
%pre><
  foo
  bar
%img

is compiled to:

<img /><pre>foo
bar</pre><img />

Note that you can make use of interpolations, for this use-case:

%span.text-small (#{$no_reviews})

(#{...} works like it works in Ruby, mostly like {$...} in PHP)

arnaud-lb avatar Jul 10 '14 16:07 arnaud-lb

@arnaud-lb, i'm quoting the documentation:

> will remove all whitespace surrounding a tag, while < will remove all whitespace immediately within a tag.

Neither works for me. From my excerpt, you can only tell about the latter, but surrounding whitespace is also not removed.

Oh, i'm also inside a foreach, as the OP. Anyway, why is this not marked as a bug?

lolmaus avatar Jul 10 '14 16:07 lolmaus

One difference, though, is that in HAML/Ruby, < also eats indentation, whereas in MtHaml it doesn't.

arnaud-lb avatar Jul 10 '14 16:07 arnaud-lb

Marked as bug

arnaud-lb avatar Jul 10 '14 16:07 arnaud-lb

One difference, though, is that in HAML/Ruby, < also eats indentation, whereas in MtHaml it doesn't.

The only reason to use whitespace removal for me is the inline-block grid technique. Whitespace adds to row width, ruining the grid. If MtHaml can't properly remove indentation, then whitespace removal is not working and thus useless.

lolmaus avatar Jul 10 '14 16:07 lolmaus

I hacked in some changes in my fork that enable me to remove whitespace using <> where I need to. It ruins pretty printing because it's not possible to determine the right thing to do in some cases (macros/conditionals output in first and last node? memory is getting fuzzy...).  From: lolmausSent: Thursday, July 10, 2014 12:45 PMTo: arnaud-lb/MtHamlReply To: arnaud-lb/MtHamlCc: chrisrichardSubject: Re: [MtHaml] whitespace removal syntax not working with php-statements (#53) One difference, though, is that in HAML/Ruby, < also eats indentation, whereas in MtHaml it doesn't.

The only reason to use whitespace removal for me is the inline-block grid technique. Whitespace adds to row width, ruining the grid. If MtHaml can't properly remove indentation, then whitespace removal is not working and thus useless.

—Reply to this email directly or view it on GitHub.

chrisrichard avatar Jul 10 '14 16:07 chrisrichard

I've tried the > and < whitespace removal outside any PHP statements, and it won't work properly:

  • > removes whitespace only after the element, while it should remove whitespace before and after the element.
  • < removes whitespace only before the content of the element, while it should remove whitespace before, between and after the containing elements.

Putting this inside a in if (true) PHP statement makes it a bit worse. The < removes linebreaks but adds space characters.

@arnaud-lb, any progress on this one?

lolmaus avatar Jul 18 '14 15:07 lolmaus

https://github.com/mervick/yii2-mthaml/issues/3

mervick avatar Apr 25 '15 21:04 mervick

Any update?

mendelk avatar May 07 '15 14:05 mendelk

Bump, it would be nice to have this fixed.

Not being able to control the white-space causes major problems with text in HTML textarea form elements.

arman-h avatar Aug 07 '15 01:08 arman-h