Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for optional (implicit) closing tags (e.g. paragraphs and list items) in Breadcrumbs, Outline and formatters #63

Open
myfonj opened this issue Jun 9, 2019 · 2 comments
Assignees
Labels
feature-request Request for new features or functionality
Milestone

Comments

@myfonj
Copy link

myfonj commented Jun 9, 2019

For HTML document

<!doctype html>
<head><title>Test</title>
<body><p>a<p>b<p>c

Placing 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

VSC Version: 1.35.0 showing above snippet and Breadcrumbs that contain aforementioned wrong multiple paragraphs nested in each other inside head.


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 -->
@aeschli
Copy link
Contributor

aeschli commented Jun 11, 2019

Thanks for the pointers. You are correct, we currently lack the handling of optional tags.

@aeschli aeschli added this to the Backlog milestone Jun 11, 2019
@aeschli aeschli added the feature-request Request for new features or functionality label Jun 11, 2019
@Tronic
Copy link

Tronic commented Jun 14, 2020

Smart indentation also misunderstands optional closing tags (nests too deep) and while working in this style the automatic insertion of the closing tag is annoying. There are very few occasions where an optional closing tag is actually needed as in nearly all practical situations a closing tag is implied at the correct position for all elements where the HTML5 specification allows optional tags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

3 participants