Sublime Forum

ST4 disable auto close of optional HTML end tags

#1

I’m using Sublime Text 4. How can I disable auto close of optional HTML end tags ?

See here the list of optional HTML end tags from W3C website : optional tags

For example : tags like “li”, “tr”, “th”, “td” must not be closed. Their end tag is optional. How auto close all HTML tags except the optional HTML end tags ?

0 Likes

#2

This is handled by a key binding:

	// HTML, XML close tag
	{ "keys": ["/"], "command": "close_tag", "args": { "insert_slash": true }, "context":
		[
			{ "key": "selector", "operator": "equal", "operand": "(text.html, text.xml) - string - comment", "match_all": true },
			{ "key": "preceding_text", "operator": "regex_match", "operand": ".*<$", "match_all": true },
			{ "key": "setting.auto_close_tags" }
		]
	}

That is, when you / after a < key, the internal close_tag command is executed to look backwards, find the appropriate tag, and close it.

That said, this won’t happen unless you actively are trying to close a tag, so that doesn’t seem like the situation you’re seeing here though (if it is, my advice is to not try to close tags you don’t want closed :wink:).

What steps are you taking that’s making the end tag appear? Wrapping selection with a tag?

0 Likes

#3

I type the folllowing :

<ul>
<li>
</

I expect that he will auto close with “</ul>”, but instead he auto close with “</li>”.

When I write on my keyboard “</ul>”, Sublime Text writes “</li>ul”. How can I avoid this without disabling auto close ?

0 Likes

#4

Aahh I see. There’s not a setting for that that I’m aware of. I would imagine that in that case you’d need a plugin to replace the built in command that replicates what it does looking backwards for tags to close, but which skips over the ones you don’t want closed.

I’m not aware of anything off the top of my head that does that however.

0 Likes

#5

Where can I find the source code of the command “close_tag” ?

0 Likes

#6

It appears to be built into the core. As such it’s code is not publicly available.

0 Likes

#7

OK, thanks for your help.

0 Likes