cvs: pear /Text_Wiki/Text/Wiki/Render/Xhtml Code.php
| From: | bertrand GUGGER | Date: | Fri, 29 Jul 2005 13:19:33 +0000 |
| Subject: | cvs: pear /Text_Wiki/Text/Wiki/Render/Xhtml Code.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-33459@lists.php.net to get a copy of this message | ||
toggg Fri Jul 29 09:19:33 2005 EDT
Modified files:
/pear/Text_Wiki/Text/Wiki/Render/Xhtml Code.php
Log:
Synching back justin's commits from tikiwiki, that's all what is ok,
the rest is buggy and introduces extra dependencies (in tikiwiki copy)
http://cvs.php.net/diff.php/pear/Text_Wiki/Text/Wiki/Render/Xhtml/Code.php?r1=1.10&r2=1.11&ty=u
Index: pear/Text_Wiki/Text/Wiki/Render/Xhtml/Code.php
diff -u pear/Text_Wiki/Text/Wiki/Render/Xhtml/Code.php:1.10
pear/Text_Wiki/Text/Wiki/Render/Xhtml/Code.php:1.11
--- pear/Text_Wiki/Text/Wiki/Render/Xhtml/Code.php:1.10 Wed Jul 20 06:08:24 2005
+++ pear/Text_Wiki/Text/Wiki/Render/Xhtml/Code.php Fri Jul 29 09:19:31 2005
@@ -1,7 +1,7 @@
<?php
class Text_Wiki_Render_Xhtml_Code extends Text_Wiki_Render {
-
+
var $conf = array(
'css' => null, // class for <pre>
'css_code' => null, // class for generic <code>
@@ -9,48 +9,49 @@
'css_html' => null, // class for HTML <code>
'css_filename' => null // class for optional filename <div>
);
-
+
/**
- *
+ *
* Renders a token into text matching the requested format.
- *
+ *
* @access public
- *
+ *
* @param array $options The "options" portion of the token (second
* element).
- *
+ *
* @return string The text rendered from the token options.
- *
+ *
*/
-
+
function token($options)
{
$text = $options['text'];
$attr = $options['attr'];
$type = strtolower($attr['type']);
-
+
$css = $this->formatConf(' class="%s"', 'css');
$css_code = $this->formatConf(' class="%s"', 'css_code');
$css_php = $this->formatConf(' class="%s"', 'css_php');
$css_html = $this->formatConf(' class="%s"', 'css_html');
$css_filename = $this->formatConf(' class="%s"',
'css_filename');
-
+
if ($type == 'php') {
-
- // PHP code example:
- // add the PHP tags
- $text = "<?php\n" . $options['text'] . "\n?>"; //
<?php
-
+ if (substr($options['text'], 0, 5) != '<?php') {
+ // PHP code example:
+ // add the PHP tags
+ $text = "<?php\n" . $options['text'] . "\n?>";
// <?php
+ }
+
// convert tabs to four spaces
$text = str_replace("\t", " ", $text);
-
+
// colorize the code block (also converts HTML entities and adds
// <code>...</code> tags)
ob_start();
highlight_string($text);
$text = ob_get_contents();
ob_end_clean();
-
+
// replace <br /> tags with simple newlines.
// replace non-breaking space with simple spaces.
// translate HTML <font> and color to XHTML <span> and style.
@@ -63,23 +64,23 @@
'color="' => 'style="color:'
);
$text = strtr($text, $map);
-
+
// get rid of the last newline inside the code block
// (becuase higlight_string puts one there)
if (substr($text, -8) == "\n</code>") {
$text = substr($text, 0, -8) . "</code>";
}
-
+
// replace all <code> tags with classed tags
if ($css_php) {
$text = str_replace('<code>', "<code$css_php>",
$text);
}
-
+
// done
$text = "<pre$css>$text</pre>";
-
+
} elseif ($type == 'html' || $type == 'xhtml') {
-
+
// HTML code example:
// add <html> opening and closing tags,
// convert tabs to four spaces,
@@ -88,7 +89,7 @@
$text = "<html>\n$text\n</html>";
$text = htmlentities($text);
$text = "<pre$css><code$css_html>$text</code></pre>";
-
+
} else {
// generic code example:
// convert tabs to four spaces,
@@ -97,12 +98,12 @@
$text = htmlentities($text);
$text = "<pre$css><code$css_code>$text</code></pre>";
}
-
+
if ($css_filename && isset($attr['filename'])) {
$text = "<div$css_filename>" .
$attr['filename'] . '</div>' . $text;
}
-
+
return "\n$text\n\n";
}
}