cvs: phd(PHD_0_4) / package.xml /formats manpage.php /include PhDHelper.class.php PhDHighlighter.class.php
| From: | Christian Weiske | Date: | Thu, 28 May 2009 07:35:09 +0000 |
| Subject: | cvs: phd(PHD_0_4) / package.xml /formats manpage.php /include PhDHelper.class.php PhDHighlighter.class.php | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-4075@lists.php.net to get a copy of this message | ||
cweiske Thu May 28 07:35:09 2009 UTC
Modified files: (Branch: PHD_0_4)
/phd package.xml
/phd/formats manpage.php
/phd/include PhDHelper.class.php PhDHighlighter.class.php
Log:
MFH: Add support for external troff highlighter in man pages
http://cvs.php.net/viewvc.cgi/phd/package.xml?r1=1.74.2.19.2.67&r2=1.74.2.19.2.68&diff_format=u
Index: phd/package.xml
diff -u phd/package.xml:1.74.2.19.2.67 phd/package.xml:1.74.2.19.2.68
--- phd/package.xml:1.74.2.19.2.67 Thu May 7 18:00:31 2009
+++ phd/package.xml Thu May 28 07:35:09 2009
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://pear.php.net/dtd/package-2.0"
xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -41,7 +41,7 @@
<active>no</active>
</developer>
- <date>2009-05-07</date>
+ <date>2009-05-28</date>
<version>
<release>0.4.8</release>
<api>0.4.8</api>
@@ -52,6 +52,7 @@
</stability>
<license uri="http://www.opensource.org/licenses/bsd-license.php">BSD
Style</license>
<notes>
+ - Add support for external troff highlighter in man pages (Christian).
</notes>
<contents>
http://cvs.php.net/viewvc.cgi/phd/formats/manpage.php?r1=1.1.2.3.2.4&r2=1.1.2.3.2.5&diff_format=u
Index: phd/formats/manpage.php
diff -u phd/formats/manpage.php:1.1.2.3.2.4 phd/formats/manpage.php:1.1.2.3.2.5
--- phd/formats/manpage.php:1.1.2.3.2.4 Thu Apr 16 15:29:34 2009
+++ phd/formats/manpage.php Thu May 28 07:35:09 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.9.2.1.2.3&r2=1.9.2.1.2.4&diff_format=u
Index: phd/include/PhDHelper.class.php
diff -u phd/include/PhDHelper.class.php:1.9.2.1.2.3 phd/include/PhDHelper.class.php:1.9.2.1.2.4
--- phd/include/PhDHelper.class.php:1.9.2.1.2.3 Mon Jan 26 21:32:44 2009
+++ phd/include/PhDHelper.class.php Thu May 28 07:35:09 2009
@@ -1,5 +1,5 @@
<?php
-/* $Id: PhDHelper.class.php,v 1.9.2.1.2.3 2009/01/26 21:32:44 cweiske Exp $ */
+/* $Id: PhDHelper.class.php,v 1.9.2.1.2.4 2009/05/28 07:35:09 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.1.2.3&r2=1.1.2.4&diff_format=u
Index: phd/include/PhDHighlighter.class.php
diff -u phd/include/PhDHighlighter.class.php:1.1.2.3 phd/include/PhDHighlighter.class.php:1.1.2.4
--- phd/include/PhDHighlighter.class.php:1.1.2.3 Mon Jan 26 21:32:44 2009
+++ phd/include/PhDHighlighter.class.php Thu May 28 07:35:09 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;
}