Sublime Forum

AutoComplete not xhtml compliant

#1

AutoComplete is a pleasure to use, but it isn’t using the correct syntax for the doctype I’m using (or the file extension of xhtml). For example, it is completing an image tag without the trailing slash:

<img src=""> instead of <img src="" />.

Also, it isn’t putting any alt attribute. Because it is required to validate, it would make sense that a blank one is inserted.

Is there any way I can change this for myself in the settings? I’ve hunted around here and in the documentation but haven’t found anything.

0 Likes

#2

Remembered I saw this when I was looking for an answer, so for future reference here’s the way I fixed it.
Navigate to the Packages folder (Preferences > Browse Packages)
Go into HTML folder and open the file named ‘html_completions.py’
Hit CTRL+F (cmd+F for Mac), type ‘img’. You’ll find a small list of tags like the below:

code,
(“embed\tTag”, “embed>”),
(“hr\tTag”, “hr>”),
(“img\tTag”, “img src=”$1">"),
(“input\tTag”, “input>”),
(“meta\tTag”, “meta>”),
(“param\tTag”, “param name=”$1" value="$2">"),[/code]

All of these need to have the closing slash added in. Here’s mine to copy and paste (be careful what you’re replacing! Don’t go breaking anything!):

code,
(“embed\tTag”, “embed/>”),
(“hr\tTag”, “hr/>”),
(“img\tTag”, “img src=”$1"/>"),
(“input\tTag”, “input/>”),
(“meta\tTag”, “meta/>”),
(“param\tTag”, “param name=”$1" value="$2"/>"),[/code]

Now with autocomplete, each tag should include the closing slash. To also include the alt attribute inside the img tag, replace the line with following:

("img\tTag", "img src=\"$1\" alt=\"$2\" />"),

Hope that helps!

0 Likes