[TxMt] Snippet to change an HTML tag

Charilaos Skiadas skiadas at hanover.edu
Sat Feb 24 06:52:25 UTC 2007


On Feb 24, 2007, at 1:17 AM, Jed Hurt wrote:
> This seems to happen quite often...
> I have:
>  <h2>Download Our Catalog</h2>
> Which needs to become:
>  <h3>Download Our Catalog</h3>
> How would I go about writing a snippet/command that would allow me to
> select "<h2>Download Our Catalog</h2>", activate the snippet, and have
> the tag become selected ("h2" in this case) and mirrored in the
> closing tag, therefore allowing me to simply type "h3" and then tab
> back out?

Put the following three lines in the command text, and set the  
command to input "selected text or line" and output "insert as  
snippet". It will even take care of things like <h2 class="foo">:

#!/usr/bin/env ruby
require ENV['TM_SUPPORT_PATH'] + "/lib/escape.rb"
print e_sn(STDIN.read).sub(/^(\s*<)([^> ]*)( [^>]*)?>/,'\\1${1:\\2}\ 
\3>').sub(/<\/([^>]*)(>\s*)$/, '</${1:\\1}\\2')


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College







More information about the textmate mailing list