Beautify script/style tags but ignore their inner JS/CSS content
See original GitHub issueGiven the following HTML input:
<body><h1>Heading</h1><script>var formatMe = function() { return false; };</script><style>.format-disabled { display: none; } </style></body>
Running a stock html_beautify
results in (as expected):
<body>
<h1>Heading</h1>
<script>
var formatMe = function() {
return false;
};
</script>
<style>
.format-disabled {
display: none;
}
</style>
</body>
However, I want to disable js-beautify
from touching anything inside <script>
and <style>
tags, so I set the following options:
{
unformatted: [ 'script', 'style' ]
}
But this results in the <script>
and <style>
tags not having newlines before them, and the closing </body>
isn’t formatted properly on its own line (edit: looks like this is #900):
<body>
<h1>Heading</h1><script>var formatMe = function() { return false; };</script><style>.format-disabled { display: none; } </style></body>
I can use the extra_liners
option to sort of force the closing body tag to wrap, but it adds two newlines instead of one:
{
unformatted: [ 'script', 'style' ],
extra_liners: [ '/body' ]
}
<body>
<h1>Heading</h1><script>var formatMe = function() { return false; };</script><style>.format-disabled { display: none; } </style>
</body>
And it seems like extra_liners
doesn’t work for <script>
and <style>
tags at all:
{
unformatted: [ 'script', 'style' ],
extra_liners: [ 'script', 'style', '/body' ]
}
<body>
<h1>Heading</h1><script>var formatMe = function() { return false; };</script><style>.format-disabled { display: none; } </style>
</body>
What I really want is this output:
<body>
<h1>Heading</h1>
<script>var formatMe = function() { return false; };</script>
<style>.format-disabled { display: none; } </style>
</body>
But it doesn’t seem possible given the current config options. Is there any way to force these outer <script>
and <style>
tags to format properly, but skip formatting everything inside of them?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top GitHub Comments
If anyone else is interested in this issue, I just posted a $300 bounty on Bountysource: https://www.bountysource.com/issues/32197949-beautify-script-style-tags-but-ignore-their-inner-js-css-content
@callmevlad - your bounty got some action on this, from two different people. Not sure whether you can split bounties. #1080 is the simpler change, but #1081 has more complete tests.
Please review and provide feedback to the submitters.