skip to Main Content

x-tmpl in VSCode

Is there a way to get VSCode to highlight the syntax inside <script type="text/x-tmpl"></script> tags?

The file is a PHP file, and shows HTML correctly, but x-tmpl is a mix of Javascript and HTML and currently it is all white.

I understand text/x-tmpl is non-standard, but I thought there might be a way to tell VSCode to treat code inside user-defined tags as a certain language?

This is the code tagged in SO as HTML, and is how I would like VSCode to show it

<script id="template-upload" type="text/x-tmpl">
    {% for (var i=0, file; file=o.files[i]; i++) { %}
        <tr class="template-upload fade show{%=o.options.loadImageFileTypes.test(file.type)?' image':''%}">
            <td>
                <span class="preview"></span>
            </td>
            <td>
                <p class="name">{%=file.name%}</p>
                <strong class="error text-danger"></strong>
            </td>
            <td>
                <p class="size">Processing...</p>
                <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="progress-bar progress-bar-success" style="width:0%;"></div></div>
            </td>
            <td>
                {% if (!o.options.autoUpload && o.options.edit && o.options.loadImageFileTypes.test(file.type)) { %}
                    <button class="btn btn-success edit" data-index="{%=i%}" disabled>
                        <i class="glyphicon glyphicon-edit"></i>
                        <span>Edit</span>
                    </button>
                {% } %}
                {% if (!i && !o.options.autoUpload) { %}
                    <button class="btn btn-primary start" disabled>
                        <i class="glyphicon glyphicon-upload"></i>
                        <span>Start</span>
                    </button>
                {% } %}
                {% if (!i) { %}
                    <button class="btn btn-warning cancel">
                        <i class="glyphicon glyphicon-ban-circle"></i>
                        <span>Cancel</span>
                    </button>
                {% } %}
            </td>
        </tr>
    {% } %}
</script>

Essentially I would like VSCode to interpret <script type="text/x-tmpl"> as <script type="text/html"> for the purposes of Syntax Highlighting

2

Answers


  1. use prettier extension on vscode

    Login or Signup to reply.
  2. That’s a similar issue to what was discussed in the #25920 issue (github.com) regarding the text/html type.

    There is no possibility to set a formatter to unique types.

    I only considered the capabilities of native VSCode. As for whether there is an extension that addresses this deficiency, I do not know.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search