-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
How to format HTML in PHP templates #845
Comments
It is unsafe, we can't format code like this: <<?php echo 'img'; ?> src="http://example.com/image.png" <?php echo attributes(); ?>>` |
So i don't think it is good idea enable this, also we have a lot of problems with |
I understand that this may be too messy or difficult to implement. Some questions: I believe the HTML parser supports formatting JS w/i Vue templates and Is there a way for this plugin to instruct the html parser to ignore PHP "nodes"? This way the HTML parser might format the HTML without mangling the PHP (as in the example output above). Thanks! |
@claytonrcarter Vue templates can be parsed by the html parser because they are html-compliant. PHP can't be parsed by the html parser because php is not html-compliant. And html can't be parsed by php parser since it's not valid php. Using a combination of parsers (php for php blocks and html for text nodes) is impossible for the majority of cases where php is intermingled with html like evilebottnawi's example because the text node is not valid html on its own, it requires the output from php to be valid. Another reason is text nodes might not actually be html, it could literally be any type of arbitrary text. |
Fair enough. This all makes complete sense and I'm realizing that this is probably the wrong place for this issue anyway. I found this issue on the main Prettier repo with some context on HTML templates: prettier/prettier#5428 |
- Please note: php-plugin can't handle files with mixed content (PHP containing HTML and/or JS and/or CSS). For reference: - prettier/plugin-php#846 - prettier/plugin-php#845 Change-Id: I40f2f013ec8f9f9557285f38bdc78190d7fb5b41
- Please note: php-plugin can't handle files with mixed content (PHP containing HTML and/or JS and/or CSS). For reference: - prettier/plugin-php#846 - prettier/plugin-php#845 Change-Id: I40f2f013ec8f9f9557285f38bdc78190d7fb5b41
- Please note: php-plugin can't handle files with mixed content (PHP containing HTML and/or JS and/or CSS). For reference: - prettier/plugin-php#846 - prettier/plugin-php#845 Change-Id: I40f2f013ec8f9f9557285f38bdc78190d7fb5b41
Prettier 1.15.2
PHP Plugin 0.9.0
Now that prettier supports formatting HTML, how can we have plugin-php format PHP and HTML in a PHP file?
Input:
Output of
prettier test.php
: (PHP is properly formatted, HTML is not.)Output of
prettier test.php --parser html
: (HTML is properly formatted, PHP is not.)Expected behavior: (Both PHP & HTML are properly formatted.)
The text was updated successfully, but these errors were encountered: