Closed expelliamus closed 3 years ago
I was able to reproduce the same issue on https://beautifier.io/ after changing the drop down to format HTML.
Could possibly be related to https://github.com/beautify-web/js-beautify/issues/1646 only need to also check for <?
to also leave alone.
when this will be fixed? thanks
Looks like they have it in the next milestone to be fixed. As soon as it's patched I'll pull the version into this extension.
Related to #18
Any update on this issue? Maybe add a temporary fix for this problem?
@MohsinEngineer So since you most likely have something else handling formatting your JS, and this extension isn't really registering itself as a formatting extension anyways so something else could handle inside script tags. You could add script tags to the content_unformatted setting. If you do this then it will simply skip the content of script tags.
"html.format.contentUnformatted": "pre,code,textarea,script"
Is there a fix coming for this anytime soon?
So the problem is upstream, you can verify that by pasting the same content - https://beautifier.io
Unfortunately the project is really hurting on contributors and isn't really going out and fixing issues with their library formatting PHP script tags as a priority.
That being said if you simply exclude the contents of script tags from formatting with this extension you can have another JS formatting library handle JS inside the tags by highlighting the code and running a formatter manually, a few exist for this task. Because this extension does not need to be registered as the primary formatting extension as explained in the docs, you can register another one as primary and this will still continue to work because it doesn't hook in there.
"html.format.contentUnformatted": "pre,code,textarea,script"
But I did actually figure out you can go...
index.php
<?php
$hi = "world";
?>
<html>
<body>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
GlobalVariables.taxonomy = "<?= $hi; ?>";
});
</script>
</body>
</html>
Then from the cmd line I ran.
php index.php
and got
<html>
<body>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
GlobalVariables.taxonomy = "world";
});
</script>
</body>
</html>
So quoting the tags works.
I am running 1.6.2, strange that I am not getting updates. So I just uninstalled and installed again and still have 1.6.2.
Either way, your other suggestion fixed my problem "html.format.contentUnformatted": "pre,code,textarea,script"
Oh, I rolled 1.6.2 like right after replying to your message so it probably slipped in before you noticed. Their update didn't do anything to mitigate the issue unfortunately. But quoting around the PHP tags should work if you don't disable, but obviously that won't be a fit for every single use case.
Glad at least we can ignore the script tags for now.
I'm thinking about another library but it's pretty slim pickings for HTML formatting, I'd welcome suggestions if anyone knows of a solid lib.
The reason for this is that, in jsbeautifier templating is turned on by default in HTML and turned off by default in JavaScript. This was done to limit the potential for breaking changes to existing users.
I suppose this default should be changed to on by default inside html <script>
tags, but that is longer term discussion.
The fix is to enble php
to the settings for jsbeautifier.
{
"html": {
"js": {
"templating": "php"
}
}
}
Filed #47 to fix this in this project.
Suppose that I have a php file which contains this:
when I save the document I get:
as you can see the extension has added spaces between the <? tag, how can I prevent this?