3 class Text_Wiki_Render_Xhtml_Code
extends Text_Wiki_Render
{
6 'css' => null
, // class for <pre>
7 'css_code' => null
, // class for generic <code>
8 'css_php' => null
, // class for PHP <code>
9 'css_html' => null
// class for HTML <code>
14 * Renders a token into text matching the requested format.
18 * @param array $options The "options" portion of the token (second
21 * @return string The text rendered from the token options.
25 function token($options)
27 $text = $options['text'];
28 $attr = $options['attr'];
29 $type = strtolower($attr['type']);
31 $css = $this->formatConf(' class="%s"', 'css');
32 $css_code = $this->formatConf(' class="%s"', 'css_code');
33 $css_php = $this->formatConf(' class="%s"', 'css_php');
34 $css_html = $this->formatConf(' class="%s"', 'css_html');
40 $text = "<?php\n" . $options['text'] . "\n?>"; // <?php
42 // convert tabs to four spaces
43 $text = str_replace("\t", " ", $text);
45 // colorize the code block (also converts HTML entities and adds
46 // <code>...</code> tags)
48 highlight_string($text);
49 $text = ob_get_contents();
52 // replace <br /> tags with simple newlines.
53 // replace non-breaking space with simple spaces.
54 // translate HTML <font> and color to XHTML <span> and style.
55 // courtesy of research by A. Kalin :-).
60 '</font>' => '</span>',
61 'color="' => 'style="color:'
63 $text = strtr($text, $map);
65 // get rid of the last newline inside the code block
66 // (becuase higlight_string puts one there)
67 if (substr($text, -8) == "\n</code>") {
68 $text = substr($text, 0, -8) . "</code>";
71 // replace all <code> tags with classed tags
73 $text = str_replace('<code>', "<code$css_php>", $text);
77 $text = "<pre$css>$text</pre>";
79 } elseif ($type == 'html' ||
$type == 'xhtml') {
82 // add <html> opening and closing tags,
83 // convert tabs to four spaces,
85 $text = str_replace("\t", " ", $text);
86 $text = "<html>\n$text\n</html>";
87 $text = htmlentities($text);
88 $text = "<pre$css><code$css_html>$text</code></pre>";
91 // generic code example:
92 // convert tabs to four spaces,
94 $text = str_replace("\t", " ", $text);
95 $text = htmlentities($text);
96 $text = "<pre$css><code$css_code>$text</code></pre>";