Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Support for script type="text/babel" in Visual Studio Code

When I'm editing the below example HTML page in Visual Studio Code (borrowed from Facebook's React tutorial and slightly edited), if I write any Javascript code in the script block, it is not syntax highlighted. But if I change the script block type to "text/javascript" then the syntax highlighting works. But then any React-y/JSX code doesn't work as it is wired to work through Babel.

Is there any way to have the script tag "type" attribute set to "text/babel" and at the same time have proper syntax highlighting in Visual Studio Code?

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>React Tutorial</title>
    <script src="https://npmcdn.com/[email protected]/dist/react.js"></script>
    <script src="https://npmcdn.com/[email protected]/dist/react-dom.js"></script>
    <script src="https://npmcdn.com/[email protected]/browser.min.js"></script>
    <script src="https://npmcdn.com/[email protected]/dist/jquery.min.js"></script>
    <script src="https://npmcdn.com/[email protected]/dist/remarkable.min.js"></script>
  </head>
  <body>
    <div id="content"></div>
    <script type="text/babel">
      ReactDOM.render(
        <div>Hello world!</div>,
        document.getElementById('content')
      );
    </script>
  </body>
</html>
like image 477
arntjw Avatar asked May 25 '26 08:05

arntjw


1 Answers

I found a solution to this now.

Open up: (VS code home dir)\resources\app\extensions\html\syntaxes\html.json, and edit the regex for the script tag. That fixed the issue for me.

like image 81
arntjw Avatar answered May 27 '26 20:05

arntjw