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 open/close tags get spaces inserted when inside <script> blocks #1685

Closed
bmewburn opened this issue Jul 6, 2019 · 2 comments
Closed

Comments

@bmewburn
Copy link

bmewburn commented Jul 6, 2019

Description

I'm using jsbeautify on mixed PHP/CSS/JS/HTML. PHP open/close tags inside script blocks get spaces inserted between the characters. I don't expect the PHP to be formatted itself, but is it possible for the tags to remain intact? It makes it easy to then find and replace with the original PHP content after formatting.

Input

The code looked like this before beautification:

<script>
var foo = <?php ?>;
var bar = <?= ?>;
</script>

Expected Output

The code should have looked like this after beautification:

<script>
    var foo = <?php ?>;
    var bar = <?= ?>;
</script>

Actual Output

The code actually looked like this after beautification:

<script>
    var foo = < ? php ? > ;
    var bar = < ? = ? > ;
</script>

Steps to Reproduce

var format = require('js-beautify');
var fs = require('fs');
var src = fs.readFileSync('./test.php').toString();
fs.writeFileSync('./formatted.php', format.html(src));

Environment

OS: Linux xps 4.9.0-9-amd64 #1 SMP Debian 4.9.168-1+deb9u3 (2019-06-16) x86_64 GNU/Linux

Settings

default settings

@bitwiseman
Copy link
Member

bitwiseman commented Jul 9, 2019

See #1647 . The area inside the script is considered javascript and processed as such.
If you have a suggestion as to how to improve the readme to make this more discoverable, I would appreciate a PR.

@bmewburn
Copy link
Author

Thanks @bitwiseman I see it now in the changelog and readme.

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

No branches or pull requests

2 participants