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

<?php ignoring ?> #532

Closed
novli opened this issue Sep 19, 2014 · 5 comments
Closed

<?php ignoring ?> #532

novli opened this issue Sep 19, 2014 · 5 comments

Comments

@novli
Copy link

novli commented Sep 19, 2014

I use your script to prettify my php scripts.
The problem is that your script thinks that tag is a single-liner, but its not.
So I've done some changes to your script to make it recognize as a comment, and it won't break my php scripts.

Can you please add such feature?

@bitwiseman
Copy link
Member

  1. Please provide an example of input, current output, and desired output.
  2. Feel free to provide a pull request will tests and perhaps we can integrate your changes.

@novli
Copy link
Author

novli commented Sep 19, 2014

For example we can have:

<?php
    $hellooo = 'world';
    $world    = 'hello';
    foreach ($array as $key => $value) {
        do->SomethingWith($value);
    }
?>

jsB converts it into:

<?php $hellooo='world' ; $world='hello' ; foreach ($array as $key=>$value) { do->SomethingWith($value); } ?>

As you can see, jsB destroys the original text. It parses the whole block as a single tag with attributes.
So I checked jsB code and found out that I can make jsB parse as a comment.
Changed line 367:

if (content[1] && content[1] === '!' || content[1] && content[1] === '?') {

Changed line 430:

} else if (tag_check.charAt(0) === '!' || tag_check.charAt(0) === '?') {

And from line 500 I added:

} else if (comment.indexOf('<?') === 0) { // <!-- php ...
    delimiter = '?>';
    matched = true;
}

I know, that it is not the best solution for this issue, but it does exactly what I need.
The only thing I'd like to have above is to indent the contents inside ... (for ... endfor, foreach ... endforeach).

@bitwiseman
Copy link
Member

That an interesting description of some changes you've made to some version of the files. It seems like the harder thing you want done is not shown in your example: "... to indent the contents inside ... (for ... endfor, foreach ... endforeach)."

In any case, I'm pretty sure what you're asking for we be better described as "php-beautify" and is thus out of scope for this any of the beautifiers we have.

But as I said, you've described some changes. Feel free to commit those changes and submit a pull request.

@novli
Copy link
Author

novli commented Sep 20, 2014

Sorry, it was nearly 4 am, so I lost some things from my mind.
It was told about lib/beautify-html.js. I changed some lines there to make your script parse php tags as comment ones.
It is just an ugly patch to avoid the problems of mine. And I can use it just for myself alone.

What I want from you is to use the idea of thinking about php tags as comment ones and make a better feature, when php content is ignored.

For your future releases I'd like your script to detect '', look inside it for 'if', 'for' and 'foreach' and indent everything until it detects the next with endif, endfor, endforeach inside. I do not know, if I can make it by myself.

@bitwiseman
Copy link
Member

I'm going to close this in favor of #490 and a new issue to track creating a php beautifier.

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

No branches or pull requests

2 participants