sublimetext-codeformatter
sublimetext-codeformatter copied to clipboard
PHP formatting with HTML
Hello, is possible add something that don't break php while formatting in HTML or that don't brake html when formatting in PHP? Is a pain every time get formatted got both?
CodeFormatter aimed to good code and good code is PHP without HTML inside and reverse :)
+1 for formating html inside php files e.g. WordPress have php + html code in templates ;)
@PixelT @Guich sorry guys but this is near to impossible to correctly format php+html (+css+js)
there are some parsers that can handle this type of code (sublime text syntax highlighter does that) but it is very complicated to format that
people can come up with very weird stuff like this
<script>
<? foreach($a as $b) { ?>
document.write("<?= $b ?>")
<? } ?>
</script>
and how the hell we are going to format this ?
CodeFormatter aimed to good code and good code is PHP without HTML inside and reverse :)
There is also a problem of context. In PHP, you never know what lives outside the closing tag (?>), it can be anything - including binary. That's why there is now way to safely mix PHP and any other formatter.
Just wondering how is this impossible if php tags are always opened & closed properly? Nearly all my jobs have files with both languages...
@v3nt you need to use some template engine instead of mixing php with html and then it will be simpler to fix formatting
for new jobs that's fine but i've got 10 years worth of older jobs where its mixed. Esp Wordpress sites.
@v3nt we don't have this feature not because we don't want to but because it is near to impossible and very difficult
This should be re-opened as it is common issue with the mixed code and codeformatter is unable to cope with it. Even worse what happens is that codeformatter tries to format PHP along HTML code and actually introducing syntax errors!
The solution instead is to turn off formatting completely for such document, if HTML is encountered.
Even better solution would be that codeformatter would tokenize the code and check starting <?php and ending ?> tags and format just the code in between. This is hardly something that is impossible to implement.
@nekromoff feel free to send pull request