Sublime Forum

Commenting Your HTML Dynamically

#1

Hello Guys, I am here for seeking help regarding Emmet plugins. Writing comments going one after another closing tag is a matter of time. We can easily comment out ending classes and ids in our HTML document. Just type |c after defining class or id of divs. It’ll comment out your classes and ids automatically according to your defines. Example: Type .container>.content>.main-article-content-preview+.sidebar|c and hit enter to see. You must have emmet installed in your ST.

Now my question to the developers, I want the comments to be shown in the same line tag closes. Generally it creates a line break before the comments. And also can you guys tell me where to edit the arguments? I want the comment text starts with “end of {my class or id name}”.

Thanks in Advance
Anwar Hussain

0 Likes

#2

Emmet is a third party plugin and not a part of Sublime Text officially. Its github page is here.

A quick examination of Emmet’s source reveals a fix that should give you what you want. In the file emmet-app.js, line 11998 (current version) we have:

			'\n<!-- /<%= attr("id", "#") %><%= attr("class", ".") %> -->',

Replace the starting \n with a space to remove the linebreak, and you can modify the rest of the string to taste as well. You’ll need to restart Sublime for changes to take effect.

Bear in mind that if you modify that file on your local installation, any update to Emmet via package control will overwrite the file and lose your changes. The solution is to add “Emmet” to the array “auto_upgrade_ignore” in package control user prefs:

	"auto_upgrade_ignore":
	
		...
		"Emmet"
	]

If these changes may be of use to you on another Sublime installation, or to other users, consider forking Emmet on github and committing your changes there. That way you’ll never lose the changes, can keep track of them and share them with others.

qgates :smile:

0 Likes

#3

[quote=“qgates”]Emmet is a third party plugin and not a part of Sublime Text officially. Its github page is here.

A quick examination of Emmet’s source reveals a fix that should give you what you want. In the file emmet-app.js, line 11998 (current version) we have:

			'\n<!-- /<%= attr("id", "#") %><%= attr("class", ".") %> -->',

Replace the starting \n with a space to remove the linebreak, and you can modify the rest of the string to taste as well. You’ll need to restart Sublime for changes to take effect.

Bear in mind that if you modify that file on your local installation, any update to Emmet via package control will overwrite the file and lose your changes. The solution is to add “Emmet” to the array “auto_upgrade_ignore” in package control user prefs:

	"auto_upgrade_ignore":
	
		...
		"Emmet"
	]

If these changes may be of use to you on another Sublime installation, or to other users, consider forking Emmet on github and committing your changes there. That way you’ll never lose the changes, can keep track of them and share them with others.

qgates :smile:[/quote]

Thank you :smile: This solved my issue.

0 Likes

#4

You don’t need to touch Emmet code to redefine closing comment, you can simply use Extensions:
docs.emmet.io/customization/
docs.emmet.io/customization/preferences/
github.com/sergeche/emmet-subli … ns-support

You can simply add

"preferences": {
    "filter.commentAfter": "<!-- /<%= attr("id", "#") %><%= attr("class", ".") %> -->"
}

in your Emmet.sublime-settings and keep your Emmet plugin auto-updated as usual.

0 Likes

#5

@Serge.che: thanks for this. I was always pissed of about how default comments are added, therefore i never used them :smiley:

Short correction about the setting:

"filter.commentAfter" : "<!-- /<%= attr(\"id\", \"#\") %><%= attr(\"class\", \".\") %> -->"

(quotes should be escaped)

0 Likes

Adding DIV class or id closing name - <!-- closing content div //--> automatically
#6

Hi, I am trying to implement this but I am struggling.
My Sublime user preferences looks like this:

{

"ignored_packages":
[
	"Vintage"
]

"filter.commentAfter": "<!-- /<%= attr(\"id\", \"#\") %><%= attr(\"class\", \".\") %> -->"
}

But looks like it cannot be parsed.
Sorry, I am not experient at all in this.

0 Likes

#7

You forgot to add a comma after the ignored_packages closing ] character.

1 Like