A wiki-markup style url filter for Drupal 5

By John Bowen, 21 November, 2008

Since I started using [Atlassian's Confluence|http://confluence.atlassian.com] in a few projects, I find myself wanting to type in wiki markup everywhere. I especially like being able to create links like this:

[Title of url|url of link]

Using this markup, you can type something like this:
[John's Blog and Stuff|http://www.gobowen.com]

...and get this:
[John's Blog and Stuff|http://www.gobowen.com]

I think that's a really easy system to remember and use. So, I took my first stab at writing a custom [module|http://www.drupal.org/project/Modules] for [Drupal|http://www.drupal.org], a [filter|http://www.drupal.org/project/Modules/category/63] that can be used in the Input Formats to produce this kind of link. Rather than start completely fresh, I copied a good deal of the concept from the [amazon filter for Drupal|http://www.drupal.org/project/amazon_filter] and just adapted it to my own purposes.

It works, but it needs work. The Regular Expression validation and matching is *very* weak. If you're reading this and want to improve on things, have a go at it and let me know how it turns out.

The code is attached. I recommend assigning it as a filter *before* the default url handler filter in Drupal...otherwise, you may get unexpected behavior.

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.