Community
Participate
Working Groups
If you format a PHP source file, the HTML code is also formatted. First thing I have to say: having an option to prevent the PHP source formatter to format HTML code (or, in general, anything outside <?php and ?>) would be extremely useful. Anyway, what is detrimental now is that the way the HTML code is "formatted" when you format a PHP source file, is unbearable and, in any case, does not follow the rules of the XML/HTML formatter of WTP. For instance, sibling tags are put all on the same line if the fit in it. I couldn't find a way to prevent this. Also, if I enable the formatter on/off tags and try to disable the formatter just before the start of the HTML code, it seems like the on/off tag is ignored, because the HTML code is formatted nevertheless. This problem makes the PHP formatter feature almost useless to me :-(
Can you write what PHP formatter you are using? E.g. broken code screenshot would be nice addition. Formatter on/off tags are probably only valid for PHP code.
Hmm... sorry, I'm not sure about your question. I'm using Ctrl+Shift+F in the PDT PHP editor to format the source code. The PHP code is correctly formatted as per the settings in PHP | Code Style | Formatter in the project properties or global Eclipse preferences. This evening I will provide you a screenshot of the result of the formatter on HTML code.
PHP code can be formatted with different profiles (from PHP | Code Style | Formatter). If you have default settings you are using PHP Conventions. I'm asking because when php file contains mixed code (e.g. PHP/HTML) PHP formatter can affect HTML formatter if there is a bug somewhere there.
Ah, you meant the profile, now it's clear. I started with the PHP Conventions profile, but then I applied some changes. I may provide you with the formatter settings file if you wish. Anyway, I couldn't find any HTML-formatting related preferences in the formatter profile editor that could help me to attenuate this behaviour on the HTML code.
I will be grateful for screenshot or code sample. I compared some basic cases with pure HTML editor and I couldn't find what is wrong. If you have same problems with not modified formatter profile then no need to attach you preferences. If problem is visible only with our settings then please attache it.
Hi Michal, sorry for the delay. Instead of a screenshot, I'm going to attach you the actual files. The first example is a pure HTML file, but with PHP extension. If you hit Ctrl+Shift+F you'll see how it is messed up. I'm using the default "PHP Conventions [built-in]".
Created attachment 254784 [details] Pure HTML - before formatting
Created attachment 254785 [details] Pure HTML - after formatting
The second example is a mixture of PHP and HTML. As you can see, meta tags inside the head tag are put on the same level as the parent tag and the div tags are apparently placed randomly...
Created attachment 254786 [details] PHP+HTML - after formatting
Created attachment 254787 [details] PHP+HTML - before formatting
Thanks for examples, Mauro. For pure HTML case try go to preferences Web->HTML Files->Editor and change Line Width to e.g. 160 and remove "input" from "Inline elements" list. Should help with formatting. Regarding PHP + HTML indeed something is messed up and we need to look at it.