question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
HookyQRcommented, Dec 10, 2016

You’ll be happy to know that the script tag is being removed from this default eventually. See https://github.com/Microsoft/vscode/commit/8eb0cce43838ea8531c1bce8f44d835d9c2060d5

1reaction
HookyQRcommented, Dec 10, 2016

Hey there. It’s not a bug, it’s caused by an unfortunate default setting in VS Code:

"html.format.unformatted": 
    "a, abbr, acronym, b, bdo, big, br, button, cite, code, dfn, 
        em, i, img, input, kbd, label, map, object, q, samp, script, 
        select, small, span, strong, sub, sup, textarea, tt, var"

If you remove script from this setting it will work as you expected.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found