Bug 466913 - Format source code messes up HTML code
Summary: Format source code messes up HTML code
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: PDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 major with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: PHP Core CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-09 13:05 EDT by Mauro Molinari CLA
Modified: 2020-05-14 10:17 EDT (History)
2 users (show)

See Also:


Attachments
Pure HTML - before formatting (990 bytes, text/plain)
2015-06-28 17:06 EDT, Mauro Molinari CLA
no flags Details
Pure HTML - after formatting (1018 bytes, text/plain)
2015-06-28 17:07 EDT, Mauro Molinari CLA
no flags Details
PHP+HTML - after formatting (1.58 KB, text/plain)
2015-06-28 17:14 EDT, Mauro Molinari CLA
no flags Details
PHP+HTML - before formatting (1.58 KB, text/plain)
2015-06-28 17:18 EDT, Mauro Molinari CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mauro Molinari CLA 2015-05-09 13:05:28 EDT
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 :-(
Comment 1 Michal Niewrzal CLA 2015-05-15 05:56:39 EDT
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.
Comment 2 Mauro Molinari CLA 2015-05-15 06:15:11 EDT
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.
Comment 3 Michal Niewrzal CLA 2015-05-15 06:19:33 EDT
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.
Comment 4 Mauro Molinari CLA 2015-05-15 06:27:20 EDT
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.
Comment 5 Michal Niewrzal CLA 2015-05-15 06:37:27 EDT
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.
Comment 6 Mauro Molinari CLA 2015-06-28 17:05:32 EDT
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]".
Comment 7 Mauro Molinari CLA 2015-06-28 17:06:41 EDT
Created attachment 254784 [details]
Pure HTML - before formatting
Comment 8 Mauro Molinari CLA 2015-06-28 17:07:50 EDT
Created attachment 254785 [details]
Pure HTML - after formatting
Comment 9 Mauro Molinari CLA 2015-06-28 17:13:03 EDT
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...
Comment 10 Mauro Molinari CLA 2015-06-28 17:14:07 EDT
Created attachment 254786 [details]
PHP+HTML - after formatting
Comment 11 Mauro Molinari CLA 2015-06-28 17:18:08 EDT
Created attachment 254787 [details]
PHP+HTML - before formatting
Comment 12 Michal Niewrzal CLA 2015-06-28 18:04:30 EDT
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.