Linking Plain URLs in Movable Type Comments

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="">Ekzemplo</a>

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


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.

Add a Comment

All comments are moderated before publication. These HTML tags are permitted: <p>, <b>, <i>, <a>, and <blockquote>. This site is protected by reCAPTCHA (for which the Google Privacy Policy and Terms of Service apply).