Vscode: [html] issue with the <template> tag

Created on 18 Apr 2016  路  4Comments  路  Source: microsoft/vscode

  • VSCode Version: 1.0.0
  • OS Version: OSX 10.11.4

Steps to Reproduce:

  1. Try to auto format the following HTML
    <template><div>Hello</div><div>World</div></template>

I expect to get something like this

<template>
____<div>Hello</div>
____<div>World</div>
</template>

But it does not work. If I replace the <template> tag with <div> then the auto format works correctly. This issue was not present in the previous version.

Thanks,

html verified

Most helpful comment

We use the beautify-html library. It has a option '"html.format.unformatted" that lists all html tags that should be kept on the same line. The default value is the list of elements named here: https://www.w3.org/TR/html5/dom.html#phrasing-content.
You see that 'template' as one of the tags that should not be formatted.
To have it formatted, you have to define the setting yourself. E.g.

"html.format.unformatted": "a,b,br,i,img,input,label,span,textarea,u,text"

All 4 comments

@aeschli do you feel responsible for HTML :-)

I can reproduce this using VSCode 1.0.0 on OSX 10.11.4 and Windows 10 with the standard Format Code shortcut (鈬р尌F) - no auto-format is required to be enabled.

As @mbergeron indicated, replacing the top-level <template/> tag with <div/> causes it to work as expected.

Context: I'm learning Aurelia where the html templates must be wrapped in <template/>. I upgraded to VSCode 1.0.0 and 鈬р尌F no longer works for html templates.

We use the beautify-html library. It has a option '"html.format.unformatted" that lists all html tags that should be kept on the same line. The default value is the list of elements named here: https://www.w3.org/TR/html5/dom.html#phrasing-content.
You see that 'template' as one of the tags that should not be formatted.
To have it formatted, you have to define the setting yourself. E.g.

"html.format.unformatted": "a,b,br,i,img,input,label,span,textarea,u,text"

For the May release I list all unformatted tags in the settings default.
I also change it to only contain inline tags. template is not part of that list and will be formatted by default.

Was this page helpful?
0 / 5 - 0 ratings