Cook Computing

MTCodeDiv Plugin

January 1, 2003 Written by Charles Cook

First of my New Year resolutions accomplished. For a while I've wanted to be able to be able to type code and XML into Movable Type entries without having to worry about converting spaces, less-than and greater-than characters to their respective entites. So I upgraded to Movable Type 2.5 1 to get support for plugins and wrote a plugin which looks for the <CODE> tag in entries and processes any enclosed text:


<CODE>
  .... code or XML here
</CODE>

For consistency with existing code samples and XML the output looks like this:


<div class="code">
  .... converted code or XML here
</div>

I didn't do much research into whether there are existing plugins to do this because I've never written anything other than "Hello World" in Perl and this was a good opportunity to write something useful, always the most fruitful way of learning a language.

Its not an ideal solution because you don't see the effect of the plugin on the entry preview page and it doesn't handle certain corner cases but its much quicker than converting the text by hand.

Testing new MTCodeDiv plugin:


using System;
 
class _
{
  static void Main()
  {
    Console.WriteLine("< Happy New Year! >");
  }
}

and some XML:


<?xml version="1.0" ?>
<message>
  <text>Happy New Year!</text>
</message>