cvs: pear /XML_Transformer/Transformer/Namespace DocBook.php

From: Date: Sun, 29 Sep 2002 10:21:34 +0000
Subject: cvs: pear /XML_Transformer/Transformer/Namespace DocBook.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-6747@lists.php.net to get a copy of this message
sebastian Sun Sep 29 06:21:34 2002 EDT Modified files: /pear/XML_Transformer/Transformer/Namespace DocBook.php Log: Some more work on the DocBook namespace handler.

Index: pear/XML_Transformer/Transformer/Namespace/DocBook.php diff -u pear/XML_Transformer/Transformer/Namespace/DocBook.php:1.12 pear/XML_Transformer/Transformer/Namespace/DocBook.php:1.13 --- pear/XML_Transformer/Transformer/Namespace/DocBook.php:1.12 Sat Sep 28 13:54:23 2002 +++ pear/XML_Transformer/Transformer/Namespace/DocBook.php Sun Sep 29 06:21:34 2002 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // -// $Id: DocBook.php,v 1.12 2002/09/28 17:54:23 sebastian Exp $ +// $Id: DocBook.php,v 1.13 2002/09/29 10:21:34 sebastian Exp $ // require_once 'XML/Transformer/Namespace.php'; @@ -36,6 +36,10 @@ * * * <emphasis> * +* * <example> +* +* * <figure> +* * * <filename> * * * <firstname> @@ -114,7 +118,7 @@ * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * Kristian Köhntopp <kris@koehntopp.de> -* @version $Revision: 1.12 $ +* @version $Revision: 1.13 $ * @access public */ class XML_Transformer_Namespace_DocBook extends XML_Transformer_Namespace { @@ -142,12 +146,36 @@ * @var array * @access private */ + var $_currentExampleNumber = ''; + + /** + * @var array + * @access private + */ + var $_currentFigureNumber = ''; + + /** + * @var array + * @access private + */ var $_currentSectionNumber = ''; /** * @var array * @access private */ + var $_examples = array(); + + /** + * @var array + * @access private + */ + var $_figures = array(); + + /** + * @var array + * @access private + */ var $_highlightColors = array( 'bg' => '#ffffff', 'comment' => '#ba8370', @@ -161,6 +189,12 @@ * @var array * @access private */ + var $_ids = array(); + + /** + * @var array + * @access private + */ var $_roles = array(); /** @@ -273,7 +307,11 @@ function start_chapter($attributes) { $this->_startSection('chapter'); - return '<div class="chapter">'; + $id = $this->_setAnchorID( + isset($attributes['id']) ? $attributes['id'] : '' + ); + + return '<div class="chapter">' . $id; } // }}} @@ -337,6 +375,70 @@ } // }}} + // {{{ function start_example($attributes) + + /** + * @param array + * @return string + * @access public + */ + function start_example($attributes) { + $this->_startSection('example'); + + $id = $this->_setAnchorID( + isset($attributes['id']) ? $attributes['id'] : '' + ); + + return '<div class="example">' . $id; + } + + // }}} + // {{{ function end_example($cdata) + + /** + * @param string + * @return string + * @access public + */ + function end_example($cdata) { + $this->_endSection('example'); + + return $cdata . '</div>'; + } + + // }}} + // {{{ function start_figure($attributes) + + /** + * @param array + * @return string + * @access public + */ + function start_figure($attributes) { + $this->_startSection('figure'); + + $id = $this->_setAnchorID( + isset($attributes['id']) ? $attributes['id'] : '' + ); + + return '<div class="figure">' . $id; + } + + // }}} + // {{{ function end_figure($cdata) + + /** + * @param string + * @return string + * @access public + */ + function end_figure($cdata) { + $this->_endSection('figure'); + + return $cdata . '</div>'; + } + + // }}} // {{{ function start_filename($attributes) /** @@ -603,7 +705,11 @@ function start_section($attributes) { $this->_startSection('section'); - return '<div class="section">'; + $id = $this->_setAnchorID( + isset($attributes['id']) ? $attributes['id'] : '' + ); + + return '<div class="section">' . $id; } // }}} @@ -657,6 +763,16 @@ return '<h2>' . $this->_currentSectionNumber . '. '; } break; + + case 'example': { + return '<h2>Example ' . $this->_currentExampleNumber; + } + break; + + case 'figure': { + return '<h2>Figure ' . $this->_currentFigureNumber; + } + break; } } @@ -677,6 +793,8 @@ break; case 'chapter': + case 'example': + case 'figure': case 'section': { return trim($cdata) . '</h2>'; } @@ -713,35 +831,83 @@ } // }}} + // {{{ function _setAnchorID($id) + + /** + * @param string + * @return string + * @access private + */ + function _setAnchorID($id) { + if (!empty($id)) { + $this->_ids[] = $id; + $id = '<a id="' . $id . '" />'; + } + + return $id; + } + + // }}} // {{{ function _startSection($type) /** * @param string - * @access public + * @access private */ function _startSection($type) { - $this->_currentSectionNumber = ''; - array_push($this->_context, $type); - if (!isset($this->_sections[$type]['open'])) { - $this->_sections[$type]['open'] = 1; - } else { - $this->_sections[$type]['open']++; - } + switch ($type) { + case 'article': + case 'chapter': + case 'section': { + $this->_currentSectionNumber = ''; - if (!isset($this->_sections[$type]['id'][$this->_sections[$type]['open']])) { - $this->_sections[$type]['id'][$this->_sections[$type]['open']] = 1; - } else { - $this->_sections[$type]['id'][$this->_sections[$type]['open']]++; - } + if (!isset($this->_sections[$type]['open'])) { + $this->_sections[$type]['open'] = 1; + } else { + $this->_sections[$type]['open']++; + } + + if (!isset($this->_sections[$type]['id'][$this->_sections[$type]['open']])) { + $this->_sections[$type]['id'][$this->_sections[$type]['open']] = 1; + } else { + $this->_sections[$type]['id'][$this->_sections[$type]['open']]++; + } + + for ($i = 1; $i <= $this->_sections[$type]['open']; $i++) { + if (!empty($this->_currentSectionNumber)) { + $this->_currentSectionNumber .= '.'; + } - for ($i = 1; $i <= $this->_sections[$type]['open']; $i++) { - if (!empty($this->_currentSectionNumber)) { - $this->_currentSectionNumber .= '.'; + $this->_currentSectionNumber .= $this->_sections[$type]['id'][$i]; + } } + break; - $this->_currentSectionNumber .= $this->_sections[$type]['id'][$i]; + case 'example': { + if (!isset($this->_examples[$this->_currentSectionNumber])) { + $this->_examples[$this->_currentSectionNumber] = 1; + } else { + $this->_examples[$this->_currentSectionNumber]++; + } + + $this->_currentExampleNumber = + $this->_currentSectionNumber . '.' . $this->_examples[$this->_currentSectionNumber]; + } + break; + + case 'figure': { + if (!isset($this->_figures[$this->_currentFigureNumber])) { + $this->_figures[$this->_currentSectionNumber] = 1; + } else { + $this->_figures[$this->_currentSectionNumber]++; + } + + $this->_currentFigureNumber = + $this->_currentSectionNumber . '.' . $this->_figures[$this->_currentSectionNumber]; + } + break; } } @@ -754,7 +920,15 @@ */ function _endSection($type) { array_pop($this->_context); - $this->_sections[$type]['open']--; + + switch ($type) { + case 'article': + case 'chapter': + case 'section': { + $this->_sections[$type]['open']--; + } + break; + } } // }}}
« previous php.pear.cvs (#6747) next »