-
Couldn't load subscription status.
- Fork 125
Description
For HTML document
<!doctype html>
<head><title>Test</title>
<body><p>a<p>b<p>cPlacing cursor at the end of the "c" paragraph makes Breadcrumbs display
head > body > p > p > p
It is incorrect per the HTML spec and in effect differs from from what happens in real HTML parsers. (It is still valid, though.)
Correct outcome should be (not considering implied HTML):
body > p
I assume it must have been discussed in the past but couldn't find any trace of prior issue.
Yes, not using optional closing tags is generally considered bad coding practice (not considering "google output compression"), and I assume that fixing this would not be a trivial task (considering complexity of specs), but current state when VSCode Outline lies about resulting HTML structure is not fortunate.
(I'm not sure about support for implied elements and their corresponding tags, but I assume it might be confusing to some seeing e.g. tbody nodes inside table that has not explicit opening tbody tag authored in the source code. But it would probably not spoil anything to see it there, since it would better reflect the reality. Different issue, perhaps?)
More verbose descriptive article
<html>
<!--
This tag does not have to be present in the source code: <html> tag (without attributes) is implied
-->
<head><!-- Ditto <head>. -->
<title>Optional closing tags test for VS Code</title>
<!-- <title> is the only mandatory tag in HTML document -->
<body>
<!--
Neither <body> is mandatory.
Presence of <body> here automatically finished <head>.
In fact occurrence of any element that is not allowed in HEAD would do the same.
-->
<p>HTML syntax tree in current Visual Studio Code is not correct.
<h2>Trivia:</h2>
<p>There are several block level elements with optional closing tags in HTML:
<dl>
<dt><code>P</code>
<dd>paragraph cannot contain block-level elements so any of them finishes it,
<dt><code>HTML</code>, <code>HEAD</code>, <code>BODY</code> <code>TBODY</code> <code>COLGROUP</code>
<dd>those are even <i>implied</i>, so even their starting tags are optional; presence of elements that belongs there creates them
<dt><code>LI</code>, <code>DT</code>, <code>DD</code>
<dd>finished by parent <code>/UL</code>, <code>/OL</code>, <code>/DL</code> or following <code>LI</code>, <code>DT</code>, <code>DD</code>
</dl>
<p>If you place cursor in the end of the source of definition list above, you'll observe
<code>html > head > body > p > p > dl > dt > dd > dt > dd > dt > dd</code> being displayed in breadcrumbs, what implies that given definition is nested in of preceding definitions what in two nested paragraphs which are children of body <i>in</i> head.
<p>It is completely different of how HTML5 conforming agent interprets it. Correct path should be <code>html > body > dl > dd</code>
<p>This affects Breacrubs and logicaly Outline and to some degree Format document action. (IIRC formatting is currently done in other library than language service, but mentioning it for completeness).
<!-- end of file finishes all opened tags -->
