Index: marksmarty.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/marksmarty/marksmarty.module,v
retrieving revision 1.21
diff -u -p -r1.21 marksmarty.module
--- marksmarty.module	22 Jan 2008 22:25:27 -0000	1.21
+++ marksmarty.module	11 Feb 2008 22:43:29 -0000
@@ -115,16 +115,48 @@ function _marksmarty_process($text, $for
   require_once(dirname(__FILE__) .'/markdown.php');
   require_once(dirname(__FILE__) .'/smartypants.php');
   if (variable_get("marksmarty_is_markdown_on_$format", 1) == 1) {
+    $geshi_compliant = variable_get("marksmarty_geshi_compliant_$format", 0);
+    if ($geshi_compliant) {
+      // geshi prepares itself and replaces tags with a square bracket notation
+      // this can produce unwanted results with markdown
+      // revert it temporarily
+      $text = preg_replace('#\[geshifilter-(([a-z]+)(?: [^\]]*)?)\](.+)\[/geshifilter-\2\]#Us',
+                            '<pre>geshi:$1|$3|$2</pre>', $text);
+    }
+    
     $text = Markdown($text);
+    
+    if ($geshi_compliant) {
+      // redo what we reverted above so that the GeSHi module can do its work
+      $text = preg_replace('#<pre>geshi:(([a-z]+)(?: [^|]*)?)\|(.+)\|\2</pre>#Us',
+                            '[geshifilter-$1]$3[/geshifilter-$2]', $text);
+      // enable plaintext style for generic code blocks & spans
+      $text = str_replace(
+                array('<pre><code>', '</code></pre>',
+                '<code>', '</code>'),
+                array('[geshifilter-blockcode]', '[/geshifilter-blockcode]',
+                '[geshifilter-code]', '[/geshifilter-code]'),
+              $text);
+    }
   }
   if (variable_get("marksmarty_is_smarty_on_$format", 1) == 1) {
     global $smartypants_attr;
     $smartypants_attr = variable_get("marksmarty_smarty_hyphens_$format", 0) + 1;
     $text = SmartyPants($text);
+    
+    if ($geshi_compliant) {
+      // &#8221; -> "
+      $text = preg_replace_callback('#\[geshifilter-[a-z]+ [^\]]+\]#U', '_marksmarty_geshipants', $text);
+    }
   }
   return $text;
 }
 
+// callback to revert &#8221; entities to double quotes
+function _marksmarty_geshipants($matches) {
+  return str_replace('&#8221;' , '"', $matches[0]);
+}
+
 function _marksmarty_settings($format) {
   require_once(dirname(__FILE__) .'/markdown.php');
   require_once(dirname(__FILE__) .'/smartypants.php');
@@ -156,6 +188,13 @@ function _marksmarty_settings($format) {
     '#default_value' => variable_get("marksmarty_smarty_hyphens_$format", 0),
     '#options' => array(0 => t('"--" for em-dashes; no en-dash support'), 1 => t('"---" for em-dashes; "--" for en-dashes'), 2 => t('"--" for em-dashes; "---" for en-dashes')),
   );
+  $form['markdown_settings']["marksmarty_geshi_compliant_$format"] = array(
+    '#type' => 'select',
+    '#title' => t('Enable GeSHi support mode'),
+    '#description' => t('When you use GeSHi rearrange the filters so that marksmarty comes before GeSHi and enable this option. When you disable HTML markup, add pre to the HTML tag whitelist.'),
+    '#default_value' => variable_get("marksmarty_geshi_compliant_$format", 0),
+    '#options' => array(0 => t('No'), 1 => t('Yes')),
+  );
 
   $links[] = 'Markdown PHP Version: <a href="http://www.michelf.com/projects/php-markdown/">'. MARKDOWN_VERSION .'</a>';
   $links[] .= 'Markdown Extra Version: '. MARKDOWNEXTRA_VERSION;
