cvs: phd /formats manpage.php /include PhDHelper.class.php PhDHighlighter.class.php
| From: | Christian Weiske | Date: | Thu, 28 May 2009 07:32:10 +0000 |
| Subject: | cvs: phd /formats manpage.php /include PhDHelper.class.php PhDHighlighter.class.php | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-4074@lists.php.net to get a copy of this message | ||
cweiske Thu May 28 07:32:10 2009 UTC
Modified files:
/phd/formats manpage.php
/phd/include PhDHelper.class.php PhDHighlighter.class.php
Log:
Add support for external troff highlighter in man pages
http://cvs.php.net/viewvc.cgi/phd/formats/manpage.php?r1=1.6&r2=1.7&diff_format=u
Index: phd/formats/manpage.php
diff -u phd/formats/manpage.php:1.6 phd/formats/manpage.php:1.7
--- phd/formats/manpage.php:1.6 Mon Apr 20 11:07:54 2009
+++ phd/formats/manpage.php Thu May 28 07:32:10 2009
@@ -189,6 +189,18 @@
/* If a chunk is being processed */
protected $chunkOpen = false;
+ /**
+ * Programlisting role. Necessary to highlight the code properly.
+ * String when role is set, false if not.
+ *
+ * @var string
+ *
+ * @see format_programlisting()
+ * @see CDATA()
+ */
+ public $role = false;
+
+
public function __construct(array $IDs) {
parent::__construct($IDs);
}
@@ -209,7 +221,7 @@
}
public function CDATA($str) {
- return str_replace("\\", "\\\\", trim($str)); // Replace \ with \\
after trimming
+ return $this->highlight(trim($str), $this->role, 'troff');
}
public function TEXT($str) {
@@ -421,6 +433,12 @@
public function format_verbatim($open, $name, $attrs, $props) {
if ($open) {
+ if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"])) {
+ $this->role = $attrs[PhDReader::XMLNS_DOCBOOK]["role"];
+ } else {
+ $this->role = false;
+ }
+
return "\n.PP\n.nf";
}
return "\n.fi";
@@ -541,4 +559,4 @@
public function toValidName($functionName) {
return str_replace(array("::", "->", "()"),
array(".", ".", ""), $functionName);
}
-}
\ No newline at end of file
+}
http://cvs.php.net/viewvc.cgi/phd/include/PhDHelper.class.php?r1=1.13&r2=1.14&diff_format=u
Index: phd/include/PhDHelper.class.php
diff -u phd/include/PhDHelper.class.php:1.13 phd/include/PhDHelper.class.php:1.14
--- phd/include/PhDHelper.class.php:1.13 Sun Jan 25 19:59:28 2009
+++ phd/include/PhDHelper.class.php Thu May 28 07:32:10 2009
@@ -1,5 +1,5 @@
<?php
-/* $Id: PhDHelper.class.php,v 1.13 2009/01/25 19:59:28 cweiske Exp $ */
+/* $Id: PhDHelper.class.php,v 1.14 2009/05/28 07:32:10 cweiske Exp $ */
/**
* Base class for PhDTheme
@@ -198,7 +198,7 @@
*
* @param string $text Text to highlight
* @param string $role Source code role to use (php, xml, html, ...)
- * @param string $format Format to highlight (pdf, html, man, ...)
+ * @param string $format Format to highlight (pdf, xhtml, troff, ...)
*
* @return string Highlighted code
*/
http://cvs.php.net/viewvc.cgi/phd/include/PhDHighlighter.class.php?r1=1.2&r2=1.3&diff_format=u
Index: phd/include/PhDHighlighter.class.php
diff -u phd/include/PhDHighlighter.class.php:1.2 phd/include/PhDHighlighter.class.php:1.3
--- phd/include/PhDHighlighter.class.php:1.2 Mon Jan 26 21:32:30 2009
+++ phd/include/PhDHighlighter.class.php Thu May 28 07:32:10 2009
@@ -2,6 +2,8 @@
/**
* Source code highlighting class for phd.
+*
+* @author Christian Weiske <cweiske@php.net>
*/
class PhDHighlighter
{
@@ -11,7 +13,7 @@
* We use a factory so you can return different objects/classes
* per format.
*
- * @param string $format Format to highlight (pdf, html, man, ...)
+ * @param string $format Output format (pdf, xhtml, troff, ...)
*
* @return PhDHighlighter Highlighter object
*/
@@ -29,13 +31,17 @@
*
* @param string $text Text to highlight
* @param string $role Source code role to use (php, xml, html, ...)
- * @param string $format Format to highlight (pdf, html, man, ...)
+ * @param string $format Output format (pdf, xhtml, troff, ...)
*
* @return string Highlighted code
*/
public function highlight($text, $role, $format)
{
- if ($format != 'xhtml') {
+ if ($format == 'troff') {
+ return "\n.PP\n.nf\n"
+ . str_replace("\\", "\\\\", trim($text))
+ . "\n.fi";
+ } else if ($format != 'xhtml') {
return $text;
}
@@ -52,4 +58,4 @@
}
-?>
\ No newline at end of file
+?>