Javascript in <script> tags in an html file is not being formatted
See original GitHub issue- Operating System (+Version): Mac OS Sierra 10.12.11
- VS Code Version: 1.7.2
- beautify Version: Latest
Provide the settings you use: (VS Code workspace and user settings, .jsbeautifyrc, .editorconfig)
Defaults
Action performed
Format html file that has javascript inside <script> tag with HookyQR.beautifyFile
command
<script>
function getListItems(listName) {
return $.ajax({
url: "/site/peak/_api/web/lists/getbytitle('" + listName + "')/items",
method: "GET",
headers: { "Accept": "application/json; odata=nometadata" },
});
}
</script>
<div class="col-xs-3">
<a href="javascript:getListItems('Categories');" class="btn btn-block btn-lg btn-success"><i class="fa fa-calendar-plus-o fa-fw"></i> Get Categories</a>
</div>
<div class="col-xs-3">
<a href="javascript:getListItems('Instructors');" class="btn btn-block btn-lg btn-success"><i class="fa fa-calendar-plus-o fa-fw"></i> Get Instructors</a>
</div>
<br />
<div id="categories"></div>
<br /><br />
<div id="instructors"></div>
Expected results
I expected the javascript inside the script tag to be formatted like the below example:
<script>
function getListItems(listName) {
return $.ajax({
url: "/site/peak/_api/web/lists/getbytitle('" + listName + "')/items",
method: "GET",
headers: { "Accept": "application/json; odata=nometadata" },
});
}
</script>
<div class="col-xs-3">
<a href="javascript:getListItems('Categories');" class="btn btn-block btn-lg btn-success"><i class="fa fa-calendar-plus-o fa-fw"></i> Get Categories</a>
</div>
<div class="col-xs-3">
<a href="javascript:getListItems('Instructors');" class="btn btn-block btn-lg btn-success"><i class="fa fa-calendar-plus-o fa-fw"></i> Get Instructors</a>
</div>
<br />
<div id="categories"></div>
<br /><br />
<div id="instructors"></div>
Actual results
The javascript was not formatted.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Should the <script> tag in HTML files not be counted ... - GitHub
I think an editor would be foolish to determine the language more precisely, because the file is the canvas and the most broad...
Read more >Python Flask list formatting not working inside script tag in HTML
The data is successfully moving into the javascript, however, it is not being interpreted as the list that I originally created. Instead, the ......
Read more >cannot format javascript when razor in script tag
cannot format javascript when razor in script tag.. ahahdung-ai ... I found a simple work around for when I first open a file...
Read more >Fix- Only properly formatted script tags can be registered
I am having a web page and i applied script manager on it. On the page load i am checking some condition and...
Read more >The Script element - HTML: HyperText Markup Language
The <script> HTML element is used to embed executable code or data; this is typically used to embed or refer to JavaScript code....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You’ll be happy to know that the
script
tag is being removed from this default eventually. See https://github.com/Microsoft/vscode/commit/8eb0cce43838ea8531c1bce8f44d835d9c2060d5Hey there. It’s not a bug, it’s caused by an unfortunate default setting in VS Code:
If you remove
script
from this setting it will work as you expected.