I run an active Movable Type-driven site where visitors include hyperlinks in their comments using HTML markup like this:

Read more on <a href="http://ekzemplo.com">Ekzemplo</a>

A lot of people don't know HTML, so they paste URLs:

Read more on http://ekzemplo.com

This is less useful and causes presentation problems when a long URL takes up more space than the site's tables can handle, pushing the right margin off the edge.

I needed to turn plain URLs into hyperlinks without messing up existing links in HTML, so I tried Brad Choate's Regex plug-in, which enables regular expressions to process any Movable Type tag's output.

With a lot of trial-and-error and the help of an online regex tester, I used the plug-in's MTRegexDefine tag to define three find-and-replace regular expressions (in Perl syntax):

A global tag attribute, regex, causes these expressions to be used on its output:

<MTCommentBody regex="1">

Plain URLs are converted to hyperlinks with their domain as the linked text. The order of the regular expressions is important; the plugin invokes hideanchor, longurl, and then showanchor in that order.

-- Rogers Cadenhead

Add a Comment

These HTML tags are permitted: p, b, i, a, and blockquote. A comment may not include more than three links. Participants in this discussion should note the site's moderation policy.