Friday 10 August 2007

Changing all HTML tags to lowercase

I'm a big fan of VIM text editor. I use it for editing HTML files as well. While I am not going to argue or prove that VIM is the best HTML editor ever (I use it a lot for HTML editing, but not just VIM), there're things where VIM shines. Really.

One part of converting from HTML to XHTML is changing all the tags to lowercase. If you open your HTML file in VIM, this task may be done with this piece of VIM magic:

:%s/<\/\?\zs\(\a\+\)\ze[ >]/\L\1/g

Note that this will change tag names only. To change tag attributes to lowercase as well, use this command:

:%s/\(<[^>]*\)\@<=\<\(\a*\)\ze=['"]/\L\2/g

No comments: