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

Don't remove empty lines in code #2

Open
kurteknikk opened this issue Jun 22, 2011 · 4 comments
Open

Don't remove empty lines in code #2

kurteknikk opened this issue Jun 22, 2011 · 4 comments

Comments

@kurteknikk
Copy link

Hi,

When i beautify code empty lines are automatically removed, but i don't want that, how can i instruct PHP_Beautifier so it never removes empty lines in my code.

I was having a look at the forum and found this topic: http://www.pear-forum.org/topic2198.html but nobody replied to it.

@Konafets
Copy link

Do you speak german? Then have a look at http://www.phphatesme.com/blog/tools/php_beautifier-eigene-filter-schreiben/

Othewise drop a note and I will translate this for you.

@pmjones
Copy link

pmjones commented Apr 28, 2012

Here is one possible fix. This class extends the Pear filter to leave blank lines in place, with their indenting as-is. Cursory eyeball testing makes me believe that it works correctly. Place it in the Beautifier directory, call it "PHP/Beautifier/Filter/PearWithLines.filter.php", and call it at the command line using --filter="PearWithLines".

<?php
require_once 'PHP/Beautifier/Filter/Pear.filter.php';
class PHP_Beautifier_Filter_PearWithLines extends PHP_Beautifier_Filter_Pear
{
    function t_whitespace($sTag) 
    {
        // remove the first series of spaces/tabs,
        // along with any \n that comes before it.
        $sTag = preg_replace("/\n?[ \t]*/m", '', $sTag, 1);
        $this->oBeaut->add($sTag);
    }
}

Hope this helps!

@Konafets
Copy link

Konafets commented May 2, 2012

I found a fork at https://github.com/jespino/PHP_Beautifier which this feature implements. Check out the whitespaces branch. It will not really keep all new lines but shrink more than one newlines into one line

@sailxjx
Copy link

sailxjx commented Sep 19, 2012

@Konafets thanks! it really helps me, and I merged @jespino 's branch into my fork PHP_Beautifier. It works!

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

No branches or pull requests

4 participants