Index: graphviz_filter.module
===================================================================
--- graphviz_filter.module	(revision 707)
+++ graphviz_filter.module	(working copy)
@@ -6,24 +6,18 @@
  * Uses PEAR::Image_GraphViz (http://pear.php.net/package/Image_GraphViz)
  */
 
-require_once('Image/GraphViz.php');
-
 function graphviz_filter_filter($op, $delta = 0, $format = -1, $text = '') {
-  if ($op == 'list') {
-    return array(
-      0 => t('Graphviz (DOT) syntax'),
-    );
+  switch ($op) {
+    case 'list':
+      return array(0 => t('Graphviz (DOT) syntax'));
+    case 'description':
+      return t('Interprets text as DOT syntax and returns a PNG image of the generated graph.');
+    case 'process':
+      $regex = "/\[graphviz\](.*?)\[\/graphviz\]/si";
+      return preg_replace_callback($regex, "_graphviz_filter_process", $text);
+    default:
+      return $text;
   }
-
-  if ($op == 'description') {
-    return t('Interprets text as DOT syntax and returns a PNG image of the generated graph.');
-  }
-
-  if ($op == 'process') {
-    return _graphviz_filter_process($text);
-  }
-
-  return $text;
 }
 
 function graphviz_filter_filter_tips($delta, $format, $long = false) {
@@ -41,7 +35,12 @@
   return $output;
 }
 
-function _graphviz_filter_process($text) {
+function _graphviz_filter_process($matches) {
+  // Don't load this unless we need to use it
+  require_once('Image/GraphViz.php');
+
+  $text = $matches[1];
+
   // Create a temporary file with the DOT script.
   $outdir = file_directory_path().'/graphviz';
   file_check_directory($outdir, FILE_CREATE_DIRECTORY);
@@ -79,7 +78,11 @@
   $formats = array();
   foreach (module_implements('graphviz_formats') as $module) {
     $f = module_invoke($module, 'graphviz_formats');
-    $formats = array_merge($formats, array_fill_keys($f, $module));
+    $out = array();
+    foreach ($f as $v) {
+      $out[$v] = $module;
+    }
+    $formats = array_merge($formats, $out);
   }
   $output = '';
   foreach (explode(',', $args['formats']) as $format) {
