cvs: pear /PHPDoc/parser PhpdocClassParser.php PhpdocConstantParser.php PhpdocParser.php PhpdocParserCore.php PhpdocUseParser.php
/PHPDoc/renderer/html PhpdocHTMLRenderer.php

From: Date: Thu, 23 Aug 2001 19:39:29 +0000
Subject: cvs: pear /PHPDoc/parser PhpdocClassParser.php PhpdocConstantParser.php PhpdocParser.php PhpdocParserCore.php PhpdocUseParser.php
/PHPDoc/renderer/html PhpdocHTMLRenderer.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-630@lists.php.net to get a copy of this message
chagenbu Thu Aug 23 15:39:29 2001 EDT Modified files: /pear/PHPDoc/parser PhpdocClassParser.php PhpdocConstantParser.php PhpdocParser.php PhpdocParserCore.php PhpdocUseParser.php /pear/PHPDoc/renderer/html PhpdocHTMLRenderer.php Log: - allow html in doc comments - be nicer about formatting. you now get pretty reasonable approximations of your formatting (paragraphs) with no extra effort, and if you toss in <pre> tags, they are honored.

Index: pear/PHPDoc/parser/PhpdocClassParser.php diff -u pear/PHPDoc/parser/PhpdocClassParser.php:1.1 pear/PHPDoc/parser/PhpdocClassParser.php:1.2 --- pear/PHPDoc/parser/PhpdocClassParser.php:1.1 Tue May 8 00:48:38 2001 +++ pear/PHPDoc/parser/PhpdocClassParser.php Thu Aug 23 15:39:28 2001 @@ -2,7 +2,7 @@ /** * Parses phpcode to extract classes and their documentation. * -* @version $Id: PhpdocClassParser.php,v 1.1 2001/05/08 04:48:38 sbergmann Exp $ +* @version $Id: PhpdocClassParser.php,v 1.2 2001/08/23 19:39:28 chagenbu Exp $ */ class PhpdocClassParser extends PhpdocFunctionParser { @@ -125,4 +125,4 @@ } // end func analyseClassDoc } // end class PhpdocClassParser -?> \ No newline at end of file +?> Index: pear/PHPDoc/parser/PhpdocConstantParser.php diff -u pear/PHPDoc/parser/PhpdocConstantParser.php:1.1 pear/PHPDoc/parser/PhpdocConstantParser.php:1.2 --- pear/PHPDoc/parser/PhpdocConstantParser.php:1.1 Tue May 8 00:48:38 2001 +++ pear/PHPDoc/parser/PhpdocConstantParser.php Thu Aug 23 15:39:28 2001 @@ -2,7 +2,7 @@ /** * Extracts define statements and their documentation from php code. * -* @version $Id: PhpdocConstantParser.php,v 1.1 2001/05/08 04:48:38 sbergmann Exp $ +* @version $Id: PhpdocConstantParser.php,v 1.2 2001/08/23 19:39:28 chagenbu Exp $ */ class PhpdocConstantParser extends PhpdocUseParser { @@ -106,4 +106,4 @@ } // end func checkConstantDoc } // end class PhpdocConstantParser -?> \ No newline at end of file +?> Index: pear/PHPDoc/parser/PhpdocParser.php diff -u pear/PHPDoc/parser/PhpdocParser.php:1.1 pear/PHPDoc/parser/PhpdocParser.php:1.2 --- pear/PHPDoc/parser/PhpdocParser.php:1.1 Tue May 8 00:48:38 2001 +++ pear/PHPDoc/parser/PhpdocParser.php Thu Aug 23 15:39:28 2001 @@ -4,7 +4,7 @@ * * Note that a lot of communication is done using shared instance variables. * -* @version $Id: PhpdocParser.php,v 1.1 2001/05/08 04:48:38 sbergmann Exp $ +* @version $Id: PhpdocParser.php,v 1.2 2001/08/23 19:39:28 chagenbu Exp $ */ class PhpdocParser extends PhpdocClassParser { @@ -280,7 +280,7 @@ */ function addClass($classname, $filename) { - $data = $this->getPhpdocParagraphs($this->phpfiles[$filename], array("modules") ); + $data = $this->getPhpdocParagraphs($this->phpfiles[$filename], array("modules")); // free memory as soon as possible... unset($this->phpfiles[$filename]); @@ -447,4 +447,4 @@ } // end func setPhpSourcecodeFiles } // end class PhpdocParser -?> \ No newline at end of file +?> Index: pear/PHPDoc/parser/PhpdocParserCore.php diff -u pear/PHPDoc/parser/PhpdocParserCore.php:1.2 pear/PHPDoc/parser/PhpdocParserCore.php:1.3 --- pear/PHPDoc/parser/PhpdocParserCore.php:1.2 Thu Aug 23 12:47:52 2001 +++ pear/PHPDoc/parser/PhpdocParserCore.php Thu Aug 23 15:39:28 2001 @@ -5,7 +5,7 @@ * Provides basic parser functions to extract doc comments, analyse tags and variable * declarations. * -* @version $Id: PhpdocParserCore.php,v 1.2 2001/08/23 16:47:52 chagenbu Exp $ +* @version $Id: PhpdocParserCore.php,v 1.3 2001/08/23 19:39:28 chagenbu Exp $ */ class PhpdocParserCore extends PhpdocParserTags { @@ -71,6 +71,7 @@ else list( , $phpcode) = $this->getModuleDoc($phpcode); + // // Find documented elements // @@ -88,15 +89,15 @@ $paragraphs["classes"][] = array( "name" => $regs[1], - "extends" => (isset($regs[2])) ? $regs[2] : "", - "doc" => $this->extractPhpdoc(substr($phpcode, $start + 3, ($end-$start) - 2)) - ); + "extends" => (isset($regs[2])) ? $regs[2] : "", + "doc" => $this->extractPhpdoc(substr($phpcode, $start + 3, ($end-$start) - 2)) + ); $classes[$regs[1]] = true; } else if ( !isset($keywords["functions"]) && preg_match($this->PHP_COMPLEX["function"], $remaining, $regs)) { $head = substr($remaining, strpos($remaining, $regs[0]) + strlen($regs[0])); - $head = substr( trim($this->getValue($head, array( "{" => true) )), 0, -1); + $head = substr(trim($this->getValue($head, array("{" => true))), 0, -1); $paragraphs["functions"][] = array( "name" => $regs[1], "doc" => $this->extractPhpdoc( substr($phpcode, $start+3, ($end-$start)-2) ), @@ -175,8 +176,8 @@ if (!isset($classes[$data[1]])) $paragraphs["classes"][] = array( "name" => $data[1], - "extends" => $data[2], - "doc" => "" + "extends" => $data[2], + "doc" => "" ); } @@ -191,17 +192,16 @@ $head = substr($phpcode, strpos($phpcode, $data[0]) + strlen($data[0])); $head = substr(trim( $this->getValue($head, array( "{" => true) )), 0, -1); $paragraphs["functions"][] = array( - "name" => $data[1], - "doc" => "", - "head" => $head - ); + "name" => $data[1], + "doc" => "", + "head" => $head + ); } - + } - + if (!isset($keywords["variables"])) { - preg_match_all($this->PHP_COMPLEX["undoc_var"], $phpcode, $regs, PREG_SET_ORDER); reset($regs); while (list($k, $data) = each($regs)) @@ -268,7 +268,7 @@ } } - + return $paragraphs; } // end func getPhpdocParagraphs @@ -338,27 +338,25 @@ // Try the remaining keywords. If one matches it's not a module doc // assume that the module doc is missing. If none matches assume that // it's a module doc which lacks the module tags. - if ( preg_match($this->PHP_COMPLEX["function"], $remaining) || - preg_match($this->PHP_COMPLEX["use"], $remaining) || - preg_match($this->PHP_COMPLEX["const"], $remaining) || - preg_match($this->PHP_COMPLEX["var"], $remaining) - ) { - - $module = array( - "doc" => "", - "status" => "missing", - "name" => "", - "group" => "" + if (preg_match($this->PHP_COMPLEX["function"], $remaining) || + preg_match($this->PHP_COMPLEX["use"], $remaining) || + preg_match($this->PHP_COMPLEX["const"], $remaining) || + preg_match($this->PHP_COMPLEX["var"], $remaining)) { + + $module = array( + "doc" => "", + "status" => "missing", + "name" => "", + "group" => "" ); - $remaining = $phpcode; - + $remaining = $phpcode; } else { $module = array( - "doc" => $doc_comment, - "status" => "tags missing", - "name" => "", - "group" => "" + 'doc' => $doc_comment, + 'status' => 'tags missing', + 'name' => '', + 'group' => '' ); } @@ -397,47 +395,46 @@ $classes = array(); - preg_match_all($this->PHP_COMPLEX["undoc_class"], $phpcode, $regs, PREG_SET_ORDER); + preg_match_all($this->PHP_COMPLEX['undoc_class'], $phpcode, $regs, PREG_SET_ORDER); reset($regs); while (list($k, $data) = each($regs)) $classes[] = array( - "name" => $data[1], - "extends" => "" + 'name' => $data[1], + 'extends' => '' ); - preg_match_all($this->PHP_COMPLEX["undoc_class_extends"], $phpcode, $regs, PREG_SET_ORDER); + preg_match_all($this->PHP_COMPLEX['undoc_class_extends'], $phpcode, $regs, PREG_SET_ORDER); reset($regs); while (list($k, $data) = each($regs)) $classes[] = array( - "name" => $data[1], - "extends" => $data[2] + 'name' => $data[1], + 'extends' => $data[2] ); return $classes; } // end func getClasses /** - * Strips "/xx", "x/" and x from doc comments (x means asterix). + * Strips '/xx', 'x/' and x from doc comments (x means asterix). * * @param string Doc comment to clean up. * @return string $phpdoc */ function extractPhpdoc($paragraph) { - $lines = split( $this->PHP_BASE["break"], $paragraph); - $phpdoc = ""; + $lines = split( $this->PHP_BASE['break'], $paragraph); + $phpdoc = ''; reset($lines); - while (list($k, $line)=each($lines)) { - - $line = trim($line); - if ("" == $line) + while (list($k, $line) = each($lines)) { + if (preg_match('/^\s*$/', $line)) { continue; + } - if ("*" == $line[0]) - $phpdoc.= trim(substr($line, 1)) . "\n"; + if (preg_match('/^\s*\*/', $line)) + $phpdoc .= preg_replace('/^\s*\*/', '', $line) . PHPDOC_LINEBREAK; else - $phpdoc.= $line . "\n"; + $phpdoc .= $line . PHPDOC_LINEBREAK; } @@ -456,33 +453,22 @@ * $description[1] = long description (second line upto the first tag) */ function getDescription($phpdoc) { - // find the position of the first doc tag $positions = $this->getTagPos($phpdoc); if (0 == count($positions)) $desc = trim($phpdoc); // no doc tags else - $desc = trim(substr($phpdoc, 0, $positions[0]["pos"])); // strip tags - - $lines = split($this->PHP_BASE["break"], $desc); - - if (1 == count($lines) || "" == $desc) { + $desc = trim(substr($phpdoc, 0, $positions[0]['pos'])); // strip tags + $lines = split($this->PHP_BASE['break'], $desc); + + if (1 == count($lines) || '' == $desc) { // only a short description but no long description - or even none of both - $description = array ($desc, ""); - + $description = array ($desc, $desc); } else { - $sdesc = trim($lines[0]); - unset($lines[0]); - - $break = $this->PHP_BASE['break']; - if ($break{0} == '[') { - $break = substr($string, 1, -1); - } - $description = array ($sdesc, implode($break, $lines)); - + $description = array($sdesc, $desc); } return $description; Index: pear/PHPDoc/parser/PhpdocUseParser.php diff -u pear/PHPDoc/parser/PhpdocUseParser.php:1.1 pear/PHPDoc/parser/PhpdocUseParser.php:1.2 --- pear/PHPDoc/parser/PhpdocUseParser.php:1.1 Tue May 8 00:48:38 2001 +++ pear/PHPDoc/parser/PhpdocUseParser.php Thu Aug 23 15:39:28 2001 @@ -3,7 +3,7 @@ * Extracts use statements (include and friends) an thheir documentation from php code. * * @author Ulf Wendel <ulf.wendel@redsys.de> -* @version $Id: PhpdocUseParser.php,v 1.1 2001/05/08 04:48:38 sbergmann Exp $ +* @version $Id: PhpdocUseParser.php,v 1.2 2001/08/23 19:39:28 chagenbu Exp $ */ class PhpdocUseParser extends PhpdocParserCore { @@ -75,4 +75,4 @@ } // end func analyseUse } // end class PhpdocUseParser -?> \ No newline at end of file +?> Index: pear/PHPDoc/renderer/html/PhpdocHTMLRenderer.php diff -u pear/PHPDoc/renderer/html/PhpdocHTMLRenderer.php:1.1 pear/PHPDoc/renderer/html/PhpdocHTMLRenderer.php:1.2 --- pear/PHPDoc/renderer/html/PhpdocHTMLRenderer.php:1.1 Tue May 8 00:48:38 2001 +++ pear/PHPDoc/renderer/html/PhpdocHTMLRenderer.php Thu Aug 23 15:39:28 2001 @@ -2,7 +2,7 @@ /** * Default HTML Renderer based on templates. * -* @version $Id: PhpdocHTMLRenderer.php,v 1.1 2001/05/08 04:48:38 sbergmann Exp $ +* @version $Id: PhpdocHTMLRenderer.php,v 1.2 2001/08/23 19:39:28 chagenbu Exp $ */ class PhpdocHTMLRenderer extends PhpdocRendererObject { @@ -49,10 +49,10 @@ } // end func path /** - * Sets the template directory. - * - * @param string - */ + * Sets the template directory. + * + * @param string + */ function setTemplateRoot($templateRoot) { if (!empty($templateRoot) && '/' != substr($templateRoot, -1)) @@ -62,18 +62,18 @@ } // end func setTemplateRoot /** - * Encodes the given string. - * - * This function gets used to encode all userdependend - * elements of the phpdoc xml files. Use it to - * customize your rendering result: beware newlines (nl2br()), - * strip tags etc. - * - * @param string String to encode - * @return string $string Encoded string - */ + * Encodes the given string. + * + * This function gets used to encode all userdependend + * elements of the phpdoc xml files. Use it to + * customize your rendering result. + * strip some tags. + * + * @param string String to encode + * @return string $string Encoded string + */ function encode($string) { - return nl2br(htmlspecialchars($string)); + return str_replace(PHPDOC_LINEBREAK . PHPDOC_LINEBREAK, '<p>', strip_tags($string, '<a>,<i>,<b>,<pre>')); } // end func encode } // end class PhpdocHTMLRenderer
« previous php.pear.cvs (#630) next »