Sublime Forum

Plugin Request: Remove an HTML attribute

#1

Hi Guys,

I know that doing this via javascript is easier I just don’t how to create a plugin in Sublime Text 2. If you guys have time can you help me on how to create this plugin? It should just remove a selected attribute.

Example:

Link

after using the plugin and selecting alt will just return:

Link

Is this possible?

TIA

0 Likes

#2

You, or perhaps someone else, would need to bear in mind that attributes can be a single word (SELECTED) and may or may not have quotes or apostrophes. (Personally, I always include double-quotes :smile: .)

Also, checks might need to be made that the user had selected a single word, and not included extra spaces, or the equal sign. Some attributes (data-*) are also hyphenated.

Given the above I won’t pursue this myself - if you are highlighting the attribute-name isn’t it just as easy to highlight the remaining text? - but someone else’s opinion may differ.

If it were extended so that first selecting, or clicking in, the tag-name would remove the whole tag (rather than just an attribute) then I can see that this would be more useful, that is, more flexible. Although, I think there might already be a plug-in that removes tags(?).

0 Likes

#3

Emmet plugin can help you: docs.emmet.io

Use “Select Item” action to quickly select attribute and remove it: docs.emmet.io/actions/select-item/

0 Likes

#4

[quote=“agibsonsw”]You, or perhaps someone else, would need to bear in mind that attributes can be a single word (SELECTED) and may or may not have quotes or apostrophes. (Personally, I always include double-quotes :smile: .)

Also, checks might need to be made that the user had selected a single word, and not included extra spaces, or the equal sign. Some attributes (data-*) are also hyphenated.

Given the above I won’t pursue this myself - if you are highlighting the attribute-name isn’t it just as easy to highlight the remaining text? - but someone else’s opinion may differ.

If it were extended so that first selecting, or clicking in, the tag-name would remove the whole tag (rather than just an attribute) then I can see that this would be more useful, that is, more flexible. Although, I think there might already be a plug-in that removes tags(?).[/quote]

Hi agibsonsw. Thank you for your response. I think this is more of like a personal plugin let say our CMS generates a pid=“12491824912” attribute in every element. If i’ll remove those pid attributes I can just press ctrl+alt+p. something like that.

by any chance, do you guys have a very easy sample for creating a plugin?

thanks again.

Imma try Emmet too :smile: cool plugin

0 Likes

#5

The BracketHighlilghter plugin has a feature that allows people to write small plugins to leverage the matching it preforms. It matches brackets and tags. I have written a bracket plugin that allows you a user to cycle through a tags attributes. You could easily adapt the code to remove pid attributes. I would personally use the Beta Branch because as soon as I finish documentation, that will be the main branch. This is the Beta Branch github.com/facelessuser/Bracket … rselect.py.

Anyways, it is another possible option.

If you choose this route and need help, just let me know.

0 Likes