cvs: phd /formats xhtml.php /themes/pear peartheme.php

From: Date: Sun, 02 Nov 2008 23:34:50 +0000
Subject: cvs: phd /formats xhtml.php /themes/pear peartheme.php
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-2362@lists.php.net to get a copy of this message
cweiske Sun Nov 2 23:34:50 2008 UTC Modified files: /phd/themes/pear peartheme.php /phd/formats xhtml.php Log: - Move nifty <p> closing and re-opening code from peartheme to xhtml format - support empty th tags

http://cvs.php.net/viewvc.cgi/phd/themes/pear/peartheme.php?r1=1.16&r2=1.17&diff_format=u Index: phd/themes/pear/peartheme.php diff -u phd/themes/pear/peartheme.php:1.16 phd/themes/pear/peartheme.php:1.17 --- phd/themes/pear/peartheme.php:1.16 Sun Nov 2 18:55:01 2008 +++ phd/themes/pear/peartheme.php Sun Nov 2 23:34:49 2008 @@ -48,7 +48,7 @@ ), 'glossentry' => 'format_suppressed_tags', 'glossdef' => 'format_glossdef', - 'glosslist' => 'dl', + 'glosslist' => 'format_dl', 'glossterm' => 'format_glossterm', 'guimenu' => 'format_guimenu', 'holder' => 'format_holder', @@ -78,12 +78,12 @@ 'itemizedlist' => 'li', ), 'literal' => 'tt', - 'literallayout' => 'p', + 'literallayout' => 'format_literallayout', 'menuchoice' => 'format_suppressed_tags', 'methodname' => 'tt', 'note' => 'format_admonition', 'para' => array( - /* DEFAULT */ 'format_para', + /* DEFAULT */ false, 'warning' => 'format_warning_para', 'important' => 'format_suppressed_tags', ), @@ -184,7 +184,7 @@ 'uri' => 'format_uri', 'userinput' => 'format_userinput', 'variablelist' => 'format_div', - 'varlistentry' => 'dl', + 'varlistentry' => 'format_dl', 'varname' => 'tt', 'warning' => 'format_warning', 'xref' => 'format_link', @@ -233,23 +233,6 @@ protected $lang = "en"; /** - * Determines if we are in a paragraph or not, and if, in which level. - * Useful to know for HTML tags that may not be in a <p> tag. - * - * @see format_para() - * - * @var integer - */ - public $openPara = 0; - - /** - * Which para levels we already escaped - * - * @var array - */ - public $escapedPara = array(); - - /** * If whitespace should be trimmed. * Helpful for programlistings that are encapsulated in <pre> tags * @@ -282,52 +265,6 @@ $this->chunked = $chunked; } - /** - * Closes a para tag when we are already in a paragraph. - * - * @return string HTML code - * - * @see $openPara - * @see restorePara() - */ - public function escapePara() - { - if (!$this->openPara) { - return ''; - } - - if (!isset($this->escapedPara[$this->openPara])) { - $this->escapedPara[$this->openPara] = 1; - return '</p>'; - } else { - ++$this->escapedPara[$this->openPara]; - return ''; - } - } - - /** - * Opens a para tag again when we escaped one before. - * - * @return string HTML code - * - * @see $openPara - * @see escapePara() - */ - public function restorePara() - { - if (!$this->openPara || !isset($this->escapedPara[$this->openPara])) { - return ''; - } - - if ($this->escapedPara[$this->openPara] == 1) { - unset($this->escapedPara[$this->openPara]); - return '<p>'; - } else { - --$this->escapedPara[$this->openPara]; - return ''; - } - } - public function format_chunk($open, $name, $attrs, $props) { $id = null; if (isset($attrs[PhDReader::XMLNS_XML]["id"])) { @@ -388,11 +325,7 @@ public function format_div($open, $name, $attrs, $props) { - if ($open) { - return $this->escapePara() - . '<div class="' . $name . '">'; - } - return '</div>' . $this->restorePara(); + return $this->format->format_div($open, $name, $attrs, $props); } public function format_exception_chunk($open, $name, $attrs, $props) { @@ -496,30 +429,12 @@ return '</' .$tag. '>'; } - /** - * Additionally to generating a <p>, the internal $openPara variable gets - * in-/decremented - * - * @return string HTML code - * - * @see $openPara - */ - public function format_para($open, $name, $attrs, $props) - { - if ($open) { - ++$this->openPara; - return '<p>'; - } - --$this->openPara; - return '</p>'; - } - public function format_para_informaltable($open, $name, $attrs, $props) { if ($open) { - return $this->escapePara() + return $this->format->escapePara() . $this->format_table($open, $name, $attrs, $props); } - return $this->format_table($open, $name, $attrs, $props) . $this->restorePara(); + return $this->format_table($open, $name, $attrs, $props) . $this->format->restorePara(); } public function format_programlisting($open, $name, $attrs) { @@ -531,12 +446,12 @@ $this->role = "default"; } - return $this->escapePara() + return $this->format->escapePara() . '<pre class="'. ($this->role ? $this->role : 'programlisting') .'" style="background-color:#EEE; width: 100%">'; } $this->role = false; $this->trim = false; - return "</pre>\n" . $this->restorePara(); + return "</pre>\n" . $this->format->restorePara(); } public function format_programlisting_text($value, $tag) { @@ -553,10 +468,20 @@ public function format_screen($open, $name, $attrs) { if ($open) { - return $this->escapePara() + return $this->format->escapePara() . '<pre class="screen" style="background-color:#EEE; width: 100%">'; } - return "</pre>\n" . $this->restorePara(); + return "</pre>\n" . $this->format->restorePara(); + } + + public function format_literallayout($open, $name, $attrs) + { + //FIXME: add support for attributes like class, continuation etc + if ($open) { + return $this->format->escapePara() + . '<p class="literallayout">'; + } + return "</p>\n" . $this->format->restorePara(); } /** @@ -654,17 +579,17 @@ public function format_admonition($open, $name, $attrs, $props) { if ($open) { - return $this->escapePara() + return $this->format->escapePara() . '<blockquote class="' . $name . '"><b>'.$this->autogen($name, $props["lang"]). ': </b>'; } - return "</blockquote>\n" . $this->restorePara(); + return "</blockquote>\n" . $this->format->restorePara(); } public function format_table($open, $name, $attrs, $props) { if ($open) { - return $this->escapePara() . '<table border="1" class="'.$name.'">'; + return $this->format->escapePara() . '<table border="1" class="'.$name.'">'; } - return "</table>\n" . $this->restorePara(); + return "</table>\n" . $this->format->restorePara(); } public function format_entry($open, $name, $attrs, $props) { @@ -710,9 +635,10 @@ public function format_warning($open, $name, $attrs, $props) { if ($open) { - return '<div class="warning" style="border: 3px double black; padding: 5px">' . "\n"; + return $this->format->escapePara() + . '<div class="warning" style="border: 3px double black; padding: 5px">' . "\n"; } - return "</div>\n"; + return "</div>\n" . $this->format->restorePara(); } public function format_warning_title($open, $name, $attrs, $props) { @@ -787,9 +713,9 @@ public function format_refsynopsisdiv($open, $name, $attrs, $props) { if ($open) { - return '<h2 class="refsynopsisdiv">Synopsis</h2><p>'; + return '<h2 class="refsynopsisdiv">Synopsis</h2>'; } - return '</p>'; + return ''; } public function format_guimenu($open, $name, $attrs, $props) { @@ -801,6 +727,11 @@ return '</i></span>'; } + public function format_dl($open, $name, $attrs, $props) + { + return $this->format->format_dl($open, $name, $attrs, $props); + } + /* FIXME: This function is a crazy performance killer */ public function qandaset($stream) { $xml = stream_get_contents($stream); @@ -873,9 +804,9 @@ public function format_calloutlist($open, $name, $attrs) { if ($open) { $this->cchunk["callouts"] = 0; - return $this->escapePara() . '<table>'; + return $this->format->escapePara() . '<table>'; } - return '</table>' . $this->restorePara(); + return '</table>' . $this->format->restorePara(); } public function format_callout($open, $name, $attrs) { if ($open) { http://cvs.php.net/viewvc.cgi/phd/formats/xhtml.php?r1=1.72&r2=1.73&diff_format=u Index: phd/formats/xhtml.php diff -u phd/formats/xhtml.php:1.72 phd/formats/xhtml.php:1.73 --- phd/formats/xhtml.php:1.72 Sat Nov 1 06:02:04 2008 +++ phd/formats/xhtml.php Sun Nov 2 23:34:49 2008 @@ -1,9 +1,9 @@ <?php -/* $Id: xhtml.php,v 1.72 2008/11/01 06:02:04 cweiske Exp $ */ +/* $Id: xhtml.php,v 1.73 2008/11/02 23:34:49 cweiske Exp $ */ class XHTMLPhDFormat extends PhDFormat { protected $elementmap = array( /* {{{ */ - 'abstract' => 'div', /* Docbook-xsl prints "abstract"... */ + 'abstract' => 'format_div', /* Docbook-xsl prints "abstract"... */ 'abbrev' => 'abbr', 'acronym' => 'acronym', 'affiliation' => 'format_suppressed_tags', @@ -14,12 +14,12 @@ /* DEFAULT */ 'format_author', 'authorgroup' => 'format_authorgroup_author', ), - 'authorgroup' => 'div', + 'authorgroup' => 'format_div', 'appendix' => 'format_container_chunk', 'application' => 'span', 'blockquote' => 'blockquote', 'bibliography' => array( - /* DEFAULT */ 'div', + /* DEFAULT */ 'format_div', 'article' => 'format_chunk', 'book' => 'format_chunk', 'part' => 'format_chunk', @@ -38,7 +38,7 @@ 'footnote' => 'format_footnote', 'footnoteref' => 'format_footnoteref', 'funcdef' => 'format_suppressed_tags', - 'funcsynopsis' => 'div', + 'funcsynopsis' => 'format_div', 'funcsynopsisinfo' => 'pre', 'function' => 'span', 'funcprototype' => 'code', @@ -47,7 +47,7 @@ 'optional' => 'span', 'honorific' => 'span', 'glossary' => array( - /* DEFAULT */ 'div', + /* DEFAULT */ 'format_div', 'article' => 'format_chunk', 'book' => 'format_chunk', 'part' => 'format_chunk', @@ -97,39 +97,39 @@ 'envar' => 'span', 'errortype' => 'span', 'errorcode' => 'span', - 'example' => 'div', + 'example' => 'format_div', 'formalpara' => 'p', 'fieldsynopsis' => array( /* DEFAULT */ 'format_fieldsynopsis', - 'entry' => 'div', + 'entry' => 'format_div', ), - 'figure' => 'div', + 'figure' => 'format_div', 'filename' => 'var', 'glossentry' => 'li', 'glossdef' => 'p', - 'glosslist' => 'ul', + 'glosslist' => 'format_itemizedlist', 'glossterm' => 'span', 'holder' => 'span', - 'imageobject' => 'div', + 'imageobject' => 'format_div', 'imagedata' => 'format_imagedata', 'important' => 'format_admonition', 'index' => array( - /* DEFAULT */ 'div', + /* DEFAULT */ 'format_div', 'article' => 'format_chunk', 'book' => 'format_chunk', 'part' => 'format_chunk', ), 'info' => array( - /* DEFAULT */ 'div', + /* DEFAULT */ 'format_div', 'note' => 'span', ), - 'informalexample' => 'div', + 'informalexample' => 'format_div', 'informaltable' => 'table', - 'indexdiv' => 'dl', + 'indexdiv' => 'format_dl', 'indexentry' => 'dd', 'initializer' => 'format_initializer', 'itemizedlist' => array( - /* DEFAULT */ 'ul', + /* DEFAULT */ 'format_itemizedlist', 'para' => 'format_para_itemizedlist', ), 'legalnotice' => 'format_legalnotice_chunk', @@ -149,10 +149,10 @@ 'modifier' => 'span', 'note' => 'format_note', 'orgname' => 'span', - 'othercredit' => 'div', + 'othercredit' => 'format_div', 'ooclass' => array( /* DEFAULT */ 'span', - 'classsynopsis' => 'div', + 'classsynopsis' => 'format_div', ), 'oointerface' => array( /* DEFAULT */ 'span', @@ -160,9 +160,9 @@ ), 'interfacename' => 'span', 'option' => 'span', - 'orderedlist' => 'ol', + 'orderedlist' => 'format_orderedlist', 'para' => array( - /* DEFAULT */ 'p', + /* DEFAULT */ 'format_para', 'example' => 'format_example_content', 'note' => 'format_note_content', 'footnote' => 'format_footnote_para', @@ -174,9 +174,9 @@ 'methodparam' => 'format_methodparam_parameter', ), 'part' => 'format_container_chunk', - 'partintro' => 'div', + 'partintro' => 'format_div', 'personname' => 'format_personname', - 'personblurb' => 'div', + 'personblurb' => 'format_div', 'phd:toc' => 'format_phd_toc', 'phrase' => 'span', 'preface' => 'format_chunk', @@ -191,7 +191,7 @@ 'classsynopsisinfo' => 'format_varname', ), 'proptype' => 'span', - 'pubdate' => 'div', /* Docbook-XSL prints "published" */ + 'pubdate' => 'format_div', /* Docbook-XSL prints "published" */ /* hack for phpdoc:varentry */ 'phpdoc:varentry' => 'format_varentry_chunk', 'refentry' => 'format_chunk', @@ -200,10 +200,10 @@ 'refsect1' => 'format_refsect', 'refsect2' => 'format_refsect', 'refsect3' => 'format_refsect', - 'refsynopsisdiv' => 'div', + 'refsynopsisdiv' => 'format_div', 'refname' => 'h1', - 'refnamediv' => 'div', - 'releaseinfo' => 'div', + 'refnamediv' => 'format_div', + 'releaseinfo' => 'format_div', 'replaceable' => 'span', 'row' => 'format_row', 'screen' => 'format_screen', @@ -220,7 +220,7 @@ 'set' => 'format_chunk', 'setindex' => 'format_chunk', 'shortaffil' => 'format_suppressed_tags', - 'simplelist' => 'ul', /* FIXME: simplelists has few attributes that need to be implemented */ + 'simplelist' => 'format_itemizedlist', /* FIXME: simplelists has few attributes that need to be implemented */ 'simpara' => array( /* DEFAULT */ 'p', 'note' => 'span', @@ -285,9 +285,9 @@ 'xref' => 'a', 'year' => 'span', 'quote' => 'format_quote', - 'qandadiv' => 'div', - 'qandaset' => 'div', - 'qandaentry' => 'dl', + 'qandadiv' => 'format_div', + 'qandaset' => 'format_div', + 'qandaentry' => 'format_dl', 'question' => 'dt', 'answer' => 'dd', ); /* }}} */ @@ -342,7 +342,32 @@ ); + /** + * Determines if we are in a paragraph or not, and if, in which level. + * Useful to know for HTML tags that may not be in a <p> tag. + * + * @see format_para() + * + * @var integer + */ + public $openPara = 0; + + /** + * Which para levels we already escaped + * + * @var array + */ + public $escapedPara = array(); + /** + * 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; /* Current Chunk variables */ protected $cchunk = array(); @@ -464,6 +489,52 @@ return $content; } + /** + * Closes a para tag when we are already in a paragraph. + * + * @return string HTML code + * + * @see $openPara + * @see restorePara() + */ + public function escapePara() + { + if (!$this->openPara) { + return ''; + } + + if (!isset($this->escapedPara[$this->openPara])) { + $this->escapedPara[$this->openPara] = 1; + return '</p>'; + } else { + ++$this->escapedPara[$this->openPara]; + return ''; + } + } + + /** + * Opens a para tag again when we escaped one before. + * + * @return string HTML code + * + * @see $openPara + * @see escapePara() + */ + public function restorePara() + { + if (!$this->openPara || !isset($this->escapedPara[$this->openPara])) { + return ''; + } + + if ($this->escapedPara[$this->openPara] == 1) { + unset($this->escapedPara[$this->openPara]); + return '<p>'; + } else { + --$this->escapedPara[$this->openPara]; + return ''; + } + } + public function format_suppressed_tags($open, $name, $attrs) { /* Ignore it */ return ""; @@ -885,6 +956,41 @@ } return ")</span>"; } + + /** + * Displays a <div> tag with the proper class name. + * Closes and re-openes <p> tags if necessary. + */ + public function format_div($open, $name, $attrs, $props) + { + if ($open) { + return $this->escapePara() + . '<div class="' . $name . '">'; + } + return '</div>' . $this->restorePara(); + } + + /** + * Additionally to generating a <p>, the internal $openPara variable gets + * in-/decremented + * + * @return string HTML code + * + * @see $openPara + */ + public function format_para($open, $name, $attrs, $props) + { + if ($props['empty']) { + return ''; + } + if ($open) { + ++$this->openPara; + return '<p class="' . $name . '">'; + } + --$this->openPara; + return '</p>'; + } + public function format_para_itemizedlist($open, $name, $attrs) { if ($open) { return "</p>\n<ul>\n"; @@ -951,9 +1057,9 @@ } public function format_variablelist($open, $name, $attrs) { if ($open) { - return "<dl>\n"; + return $this->escapePara() . "<dl>\n"; } - return "</dl>\n"; + return "</dl>\n" . $this->restorePara(); } public function format_varlistentry($open, $name, $attrs) { if ($open) { @@ -1104,6 +1210,30 @@ return '<img src="' .$attrs[PhDReader::XMLNS_DOCBOOK]["fileref"]. '" />'; } + public function format_dl($open, $name, $attrs, $props) + { + if ($open) { + return $this->escapePara() . '<dl class="' . $name . '">'; + } + return '</dl>' . $this->restorePara(); + } + + public function format_itemizedlist($open, $name, $attrs, $props) + { + if ($open) { + return $this->escapePara() . '<ul class="' . $name . '">'; + } + return '</ul>' . $this->restorePara(); + } + + public function format_orderedlist($open, $name, $attrs, $props) + { + if ($open) { + return $this->escapePara() . '<ol>'; + } + return '</ol>' . $this->restorePara(); + } + public function format_table($open, $name, $attrs, $props) { if ($open) { $this->cchunk["table"] = true; @@ -1186,7 +1316,10 @@ } return "</tr>\n"; } - public function format_th_entry($open, $name, $attrs) { + public function format_th_entry($open, $name, $attrs, $props) { + if ($props["empty"]) { + return '<th class="empty">&nbsp;</th>'; + } if ($open) { $colspan = PhDFormat::colspan($attrs[PhDReader::XMLNS_DOCBOOK]); if ($colspan == 1) {
« previous php.doc.cvs (#2362) next »