compulim / vscode-closetag

Quickly close last opened HTML/XML tag in Visual Studio Code
14 stars 5 forks source link

Still closes void elements immediately preceding the cursor #9

Closed evanwarner closed 7 years ago

evanwarner commented 7 years ago

With 1.0.0, your fix for #8 works better now, but if a void element is the first thing hit during the walkback, it still closes that instead of skipping it. If I have <main><article><section><div><span><img>(cursor here) then it closes the <img> first before the others. But if I have <main><article><section><div><span><img></span>(cursor here) then it correctly starts with the </div>.

compulim commented 7 years ago

I understand that closing void elements is annoying. But IMHO, all void elements should be self-closed for clarity.

I added a new configuration option closeTag.ignoreTags to ignore certain tags, possibilities are:

By default, it ignore nothing. You may want to set it to html so the engine will ignore HTML set of void elements.

The feature is out now on 1.1.0.

Enjoy!

evanwarner commented 7 years ago

Cool, thanks. If it were me I'd make 'html' the default ignore (since I'd wager that an overwhelming majority of users will be writing HTML), but it works well now.

FYI, from the HTML 5.2 spec:

Void elements only have a start tag; end tags must not be specified for void elements.

compulim commented 7 years ago

That's cool it now fit your scenario.

In HTML spec:

Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single "/" (U+002F) character. This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.

So void element can be a self-closing start tag without end tag, making them XML-friendly. 😉

evanwarner commented 7 years ago

Right, but the existence of the self-closing / on the void element is independent of the fact that there should not be an actual separate closing tag, which is what this plugin creates unless I set "closeTag.ignoreTags" = "html".

compulim commented 7 years ago

And now I am thinking to have an "auto" option. When the document is in HTML mode, it should automatically applies the HTML void set.

Will open a new issue on that. (Updated: issue #10)

Btw, thanks for your insight on HTML void tags.