Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio thinks empty HTML5 tags should end with a slash in ASP

When using Visual Studio 2013 or 2015 (any edition) and working with a file ending in .asp or .aspx, it will always show the warning Empty elements such as 'input' must end with />. This happens even when I change the doctype of the editor from HTML5 to HTML 4.01. I believe the editor goes into 'HTML (Web Forms)' mode when opening these files.

HTML5 screenshot

HTML 4.01 screenshot

When working with the same file using a .html extension, this does not happen, and in fact, I cannot change the doctype of the editor in this mode anyway.

Can anyone find a workaround for this problem, or should I be reporting it to MS as a bug?

PS. This question is not the same as Visual Studio uses XHTML tag closing for HTML5 tags.

Edit: example code below.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Test</title>
</head>
<body>
    <form method="post" action="?" class="form-horizontal">
        <div class="form-group">
            <label class="col-sm-4 control-label" for="test">Test<span class="required-field">*</span></label>
            <div class="col-sm-8">
                <input class="form-control" type="text" maxlength="100" id="test" name="test" size="40" value="1" required>
            </div>
        </div>
    </form>
</body>
</html>

Edit 2: When editing the Text Editor options for HTML, there's a subsection called Formatting that lets you choose XHTML coding style on/off, but there's no such setting for HTML (Web Forms).

HTML coding style

Additionally, HTML (Web Forms) has the Tag Specific Options window, but even when setting the closing tag on 'input' to 'No closing tag' the issue still occurs.

Tag specific options

like image 727
BoffinBrain Avatar asked Oct 19 '22 11:10

BoffinBrain


1 Answers

I've researched the issue for a bit and my conclusion is that it is indeed a bug in the markup validation.

HTML5 doesn't require input to have a closing character and the change in validation does happen, because using an XHTML doctype also shows a warning for the meta tag, not only for input.

There are several default editors as one can see when using Open With to open an aspx file. The default is "Web Forms Editor", but one can choose "HTML Editor" (not recommended, as it doesn't understand directives) as well as "HTML (Web Forms) Editor", any of which you can set as default.

I tried to see if I can change things by altering "C:\Program Files\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Schemas\1033\HTML\html.xsd" (look for vs:description="83", the id of the input element) and at first glance it seems to be only for intellisense and autocompletion.

I believe that the difference between input and meta is that input is supposed to be a tag that can become a server tag. Probably it becomes problematic to handle it as a normal tag.

Other than disassembling editors in "C:\Program Files\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Editors\" I see no other direction of investigation. It is curious that I have not seen this reported elsewhere on the web, though.

like image 150
Siderite Zackwehdex Avatar answered Oct 21 '22 05:10

Siderite Zackwehdex