Saturday, September 11, 2010

UltraEdit macro for outputting anchor tags in HTML

One of the most common (and therefore painful) HTML elements to write repeatedly is an anchor tag. There is so much detail to fill in. First you have to write the A tag itself, opening and closing it. Then you have to copy and paste the URL from your browser into an HREF attribute, then you have to cursor into the middle of it and think of something descriptive to write for the display text. It's just so much hard work!

<a href="http://robertmarkbramprogrammer.blogspot.com">my blog</a>

I do most of my coding "by hand" in the wonderful and amazing UltraEdit which is extensible through, among other means, a macro language. Here is my macro for outputting anchor tags. I promise that this macro will make you truly enjoy coding HTML again. In fact, I had two weeks annual leave coming up which I was going to spend on the beach with my partner: but I cancelled it just so that I could spend the time hand coding the HTML for more blog posts! That's right - this macro really is that good.

Use it by first copying the URL you need; then type your display text, select it and run this macro: it will correctly output <a href="copied url">selected display text</a>| and leave the cursor where the pipe character is.

InsertMode
ColumnModeOff
HexOff
IfSel
Clipboard 9
Cut
"<a href=""
Clipboard 0
Paste
"">"
Clipboard 9
Paste
Clipboard 0
"</a>"
Else
"<a href=""
Paste
""></a>"
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
EndIf

Alternatively, you can use it without typing and selecting the display text: copy the URL you need and then run this macro: it will output <a href="copied url">|</a> and leave the cursor where the pipe character is.