Home Download Buy Blog Forum Support

Plugin Request: Remove an HTML attribute

Plugin Request: Remove an HTML attribute

Postby jchvelasco on Tue Dec 04, 2012 10:36 pm

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:

<a href="#" alt="removeMe">Link</a>

after using the plugin and selecting alt will just return:

<a href="#">Link</a>

Is this possible?

TIA
jchvelasco
 
Posts: 2
Joined: Tue Dec 04, 2012 10:33 pm

Re: Plugin Request: Remove an HTML attribute

Postby agibsonsw on Wed Dec 05, 2012 9:02 pm

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 :) .)

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(?).
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Plugin Request: Remove an HTML attribute

Postby serge.che on Fri Dec 07, 2012 8:04 pm

Emmet plugin can help you: http://docs.emmet.io

Use “Select Item” action to quickly select attribute and remove it: http://docs.emmet.io/actions/select-item/
serge.che
 
Posts: 6
Joined: Fri Nov 09, 2012 9:57 am

Re: Plugin Request: Remove an HTML attribute

Postby jchvelasco on Tue Dec 11, 2012 3:56 pm

agibsonsw wrote: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 :) .)

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(?).


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 :) cool plugin
jchvelasco
 
Posts: 2
Joined: Tue Dec 04, 2012 10:33 pm

Re: Plugin Request: Remove an HTML attribute

Postby facelessuser on Wed Dec 12, 2012 12:38 am

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 https://github.com/facelessuser/Bracket ... r/tree/BH2. Granted what you would want would be much simpler than cycling through the attributes, but the attribute select plugin is found here in the repo: https://github.com/facelessuser/Bracket ... rselect.py.

Anyways, it is another possible option.

If you choose this route and need help, just let me know.
facelessuser
 
Posts: 1567
Joined: Tue Apr 05, 2011 7:38 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 6 guests