cvs: phd /phpdotnet/phd Config.php Format.php Highlighter.php
| From: | Moacir de Oliveira Miranda Júnior | Date: | Mon, 22 Jun 2009 01:22:52 +0000 |
| Subject: | cvs: phd /phpdotnet/phd Config.php Format.php Highlighter.php | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-4192@lists.php.net to get a copy of this message | ||
moacir Mon Jun 22 01:22:52 2009 UTC
Modified files:
/phd/phpdotnet/phd Config.php Format.php Highlighter.php
Log:
Highlighter added in Format.php
http://cvs.php.net/viewvc.cgi/phd/phpdotnet/phd/Config.php?r1=1.61&r2=1.62&diff_format=u
Index: phd/phpdotnet/phd/Config.php
diff -u phd/phpdotnet/phd/Config.php:1.61 phd/phpdotnet/phd/Config.php:1.62
--- phd/phpdotnet/phd/Config.php:1.61 Sat Jun 20 06:55:41 2009
+++ phd/phpdotnet/phd/Config.php Mon Jun 22 01:22:52 2009
@@ -1,6 +1,6 @@
<?php
namespace phpdotnet\phd;
-/* $Id: Config.php,v 1.61 2009/06/20 06:55:41 moacir Exp $ */
+/* $Id: Config.php,v 1.62 2009/06/22 01:22:52 moacir Exp $ */
define("PHD_VERSION", "phd-from-cvs");
@@ -38,7 +38,7 @@
'user_error_color' => false,
'phd_info_output' => NULL,
'phd_info_color' => false,
- 'highlighter' => '\phpdotnet\phd\Highlighter',
+ 'highlighter' => "phpdotnet\\phd\\Highlighter",
'package' => 'PHP',
);
http://cvs.php.net/viewvc.cgi/phd/phpdotnet/phd/Format.php?r1=1.3&r2=1.4&diff_format=u
Index: phd/phpdotnet/phd/Format.php
diff -u phd/phpdotnet/phd/Format.php:1.3 phd/phpdotnet/phd/Format.php:1.4
--- phd/phpdotnet/phd/Format.php:1.3 Sat Jun 20 06:55:41 2009
+++ phd/phpdotnet/phd/Format.php Mon Jun 22 01:22:52 2009
@@ -16,6 +16,9 @@
private static $autogen = array();
+ /* PhDHelper */
+ private static $highlighters = array();
+
public function __construct() {
if (file_exists(Config::output_dir() . "index.sqlite")) {
$this->sqlite = new \SQLite3(Config::output_dir() . 'index.sqlite');
@@ -66,7 +69,6 @@
return $context;
}
-
final public function notify($event, $val = null) {
$this->update($event, $val);
foreach($this as $format) {
@@ -81,7 +83,7 @@
}
final public function attach($obj, $inf = array()) {
if (!($obj instanceof $this) && get_class($obj) != get_class($this)) {
- throw new \InvalidArgumentException(get_class($this) . " themes *MUST* _inherit_
" .get_class($this). ", got " . get_class($obj));
+ throw new InvalidArgumentException(get_class($this) . " themes *MUST* _inherit_
" .get_class($this). ", got " . get_class($obj));
}
$obj->notify(Render::STANDALONE, false);
return parent::attach($obj, $inf);
@@ -121,7 +123,7 @@
}
final public static function autogen($text, $lang) {
- if ($lang === NULL) {
+ if ($lang == NULL) {
$lang = Config::language();
}
if (isset(self::$autogen[$lang])) {
@@ -136,7 +138,7 @@
$filename = Config::lang_dir() . $lang . ".xml";
- $r = new \XMLReader();
+ $r = new \XMLReader;
if (!file_exists($filename) || !$r->open($filename)) {
if ($lang == Config::fallback_language()) {
throw new \Exception("Cannot open $filename");
@@ -269,6 +271,30 @@
return 1;
}
/* }}} */
+
+ /*PhDHelper functions*/
+
+ /**
+ * Highlight (color) the given piece of source code
+ *
+ * @param string $text Text to highlight
+ * @param string $role Source code role to use (php, xml, html, ...)
+ * @param string $format Format to highlight (pdf, xhtml, troff, ...)
+ *
+ * @return string Highlighted code
+ */
+ public function highlight($text, $role = 'php', $format = 'xhtml')
+ {
+ if (!isset(self::$highlighters[$format])) {
+ $class = Config::highlighter();
+ self::$highlighters[$format] = $class::factory($format);
+ }
+
+ return self::$highlighters[$format]->highlight(
+ $text, $role, $format
+ );
+ }
+
}
/*
http://cvs.php.net/viewvc.cgi/phd/phpdotnet/phd/Highlighter.php?r1=1.3&r2=1.4&diff_format=u
Index: phd/phpdotnet/phd/Highlighter.php
diff -u phd/phpdotnet/phd/Highlighter.php:1.3 phd/phpdotnet/phd/Highlighter.php:1.4
--- phd/phpdotnet/phd/Highlighter.php:1.3 Thu May 28 07:32:10 2009
+++ phd/phpdotnet/phd/Highlighter.php Mon Jun 22 01:22:52 2009
@@ -1,11 +1,12 @@
<?php
+namespace phpdotnet\phd;
/**
* Source code highlighting class for phd.
*
* @author Christian Weiske <cweiske@php.net>
*/
-class PhDHighlighter
+class Highlighter
{
/**
* Create a new highlighter instance for the given format.