Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

whitespace removal syntax not working with php-statements #53

Open
stmh opened this issue Mar 25, 2014 · 12 comments
Open

whitespace removal syntax not working with php-statements #53

stmh opened this issue Mar 25, 2014 · 12 comments
Labels

Comments

@stmh
Copy link

stmh commented Mar 25, 2014

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?

@chrisrichard
Copy link

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.

@lolmaus
Copy link
Contributor

lolmaus commented Jul 10, 2014

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_

@arnaud-lb
Copy link
Owner

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)

@lolmaus
Copy link
Contributor

lolmaus commented Jul 10, 2014

@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?

@arnaud-lb
Copy link
Owner

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

@arnaud-lb arnaud-lb added the bug label Jul 10, 2014
@arnaud-lb
Copy link
Owner

Marked as bug

@lolmaus
Copy link
Contributor

lolmaus commented Jul 10, 2014

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.

@chrisrichard
Copy link

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.

@lolmaus
Copy link
Contributor

lolmaus commented Jul 18, 2014

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?

@mervick
Copy link
Contributor

mervick commented Apr 25, 2015

mervick/yii2-mthaml#3

@mendelk
Copy link

mendelk commented May 7, 2015

Any update?

@arman-h
Copy link

arman-h commented Aug 7, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants