Use Horde_Mime_Viewer_SyntaxHighlighter in Wicked
authorChuck Hagenbuch <chuck@horde.org>
Sat, 2 Oct 2010 21:05:03 +0000 (17:05 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Sat, 2 Oct 2010 21:05:30 +0000 (17:05 -0400)
wicked/lib/Text_Wiki/Render/Xhtml/Code2.php

index 63ca0d4..bb22216 100644 (file)
@@ -7,9 +7,6 @@ require_once 'Text/Wiki/Render/Xhtml/Code.php';
  */
 class Text_Wiki_Render_Xhtml_Code2 extends Text_Wiki_Render_Xhtml_Code
 {
-    protected $_shLoaded = false;
-    protected $_shBrushes = array();
-
     /**
      * Renders a token into text matching the requested format.
      *
@@ -21,74 +18,14 @@ class Text_Wiki_Render_Xhtml_Code2 extends Text_Wiki_Render_Xhtml_Code
     function token($options)
     {
         $type = $options['attr']['type'];
-        switch ($type) {
-        case 'php':
-        case 'htmlphp':
-            $type = 'php';
-            $brush = 'Php';
-            break;
-
-        case 'xml':
-        case 'html':
-        case 'xhtml':
-        case 'xslt':
-            $brush = 'Xml';
-            break;
-
-        case 'bash':
-        case 'shell':
-            $brush = 'Bash';
-            break;
-
-        case 'diff':
-        case 'patch':
-        case 'pas':
-            $brush = 'Diff';
-            break;
-
-        case 'css':
-            $brush = 'Css';
-            break;
-
-        case 'c':
-        case 'cpp':
-            $brush = 'Cpp';
-            break;
-
-        case 'java':
-            $brush = 'Java';
-            break;
-
-        case 'js':
-        case 'jscript':
-        case 'javascript':
-            $brush = 'JScript';
-            break;
-
-        default:
-            return parent::token($options);
-        }
-
-        if (!$this->_shLoaded) {
-            Horde::addScriptFile('syntaxhighlighter/scripts/shCore.js', 'horde', true);
-            Horde::addInlineScript(array(
-                'SyntaxHighlighter.defaults[\'toolbar\'] = false;',
-                'SyntaxHighlighter.all();',
-            ), 'dom');
-            $this->_shLoaded = true;
 
-            $sh_js_fs = $GLOBALS['injector']->getInstance('Horde_Registry')->get('jsfs', 'horde') . '/syntaxhighlighter/styles/';
-            $sh_js_uri = Horde::url($GLOBALS['injector']->getInstance('Horde_Registry')->get('jsuri', 'horde'), false, -1) . '/syntaxhighlighter/styles/';
-            Horde_Themes::includeStylesheetFiles(array('additional' => array(
-                array('f' => $sh_js_fs . 'shCoreEclipse.css', 'u' => $sh_js_uri . 'shCoreEclipse.css'),
-                array('f' => $sh_js_fs . 'shThemeEclipse.css', 'u' => $sh_js_uri . 'shThemeEclipse.css'),
-            )));
-        }
-        if (empty($this->_shBrushes[$brush])) {
-            Horde::addScriptFile('syntaxhighlighter/scripts/shBrush' . $brush . '.js', 'horde', true);
-            $this->_shBrushes[$brush] = true;
-        }
+        $part = new Horde_Mime_Part();
+        $part->setContents($options['text']);
+        $part->setType("x-extension/$type");
 
-        return '<pre class="brush: ' . $type . '">' . htmlspecialchars($options['text']) . '</pre>';
+        $viewer = new Horde_Mime_Viewer_SyntaxHighlighter($part, array('charset' => $GLOBALS['registry']->getCharset()));
+        $data = $viewer->render('inline');
+        $data = reset($data);
+        return $data['data'];
     }
 }