Source for file DocBook.php
Documentation is available at DocBook.php
// +---------------------------------------------------------------------------+
// | PEAR :: XML :: Transformer :: DocBook Namespace Handler |
// +---------------------------------------------------------------------------+
// | Copyright (c) 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> and |
// +---------------------------------------------------------------------------+
// | This source file is subject to version 3.00 of the PHP License, |
// | that is available at http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +---------------------------------------------------------------------------+
require_once 'XML/Transformer/Namespace.php';
require_once 'XML/Util.php';
* DocBook Namespace Handler.
* This namespace handler provides transformations to render a subset of
* the popular DocBook/XML markup (http://www.docbook.org/) into HTML.
* Transformations for the following DocBook tags are implemented:
* require_once 'XML/Transformer/Driver/OutputBuffer.php';
* $t = new XML_Transformer_Driver_OutputBuffer(
* 'autoload' => 'DocBook'
* <title>An Article</title>
* <firstname>Sebastian</firstname>
* <surname>Bergmann</surname>
* <title>Section One</title>
* <title>Section Two</title>
* Sebastian Bergmann: An Article
* Sebastian Bergmann: An Article
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
* @package XML_Transformer
var $_currentExampleNumber = '';
var $_currentFigureNumber = '';
var $_currentSectionNumber = '';
var $_examples = array ();
var $_highlightColors = array (
var $_secondPass = FALSE;
var $_sections = array ();
// {{{ function XML_Transformer_Namespace_DocBook($parameters = array())
if (isset ($parameters['highlightColors'])) {
$this->_highlightColors = $parameters['highlightColors'];
foreach ($this->_highlightColors as $highlight => $color) {
ini_set('highlight.' . $highlight, $color);
// {{{ function start_artheader($attributes)
if (!$this->_secondPass) {
XML_Util ::attributesToString ($attributes)
// {{{ function end_artheader($cdata)
if (!$this->_secondPass) {
$cdata = $cdata . '</artheader>';
// {{{ function start_article($attributes)
return $this->_startDocument ('article', $attributes);
// {{{ function end_article($cdata)
return $this->_endDocument ('article', $cdata);
// {{{ function start_author($attributes)
// {{{ function end_author($cdata)
// {{{ function start_book($attributes)
return $this->_startDocument ('book', $attributes);
// {{{ function end_book($cdata)
return $this->_endDocument ('book', $cdata);
// {{{ function start_chapter($attributes)
$id = $this->_startSection (
isset ($attributes['id']) ? $attributes['id'] : ''
return '<div class="chapter">' . $id;
// {{{ function end_chapter($cdata)
$this->_endSection ('chapter');
return $cdata . '</div>';
// {{{ function start_emphasis($attributes)
$emphasisRole = isset ($attributes['role']) ? $attributes['role'] : '';
$this->_roles['emphasis'] = 'b';
$this->_roles['emphasis'] = 'i';
return '<' . $this->_roles['emphasis'] . '>';
// {{{ function end_emphasis($cdata)
$this->_roles['emphasis']
$this->_roles['emphasis'] = '';
// {{{ function start_example($attributes)
$id = $this->_startSection (
isset ($attributes['id']) ? $attributes['id'] : ''
return '<div class="example">' . $id;
// {{{ function end_example($cdata)
$this->_endSection ('example');
return $cdata . '</div>';
// {{{ function start_figure($attributes)
$id = $this->_startSection (
isset ($attributes['id']) ? $attributes['id'] : ''
return '<div class="figure">' . $id;
// {{{ function end_figure($cdata)
$this->_endSection ('figure');
return $cdata . '</div>';
// {{{ function start_filename($attributes)
// {{{ function end_filename($cdata)
return trim($cdata) . '</tt>';
// {{{ function start_firstname($attributes)
// {{{ function end_firstname($cdata)
// {{{ function start_function($attributes)
// {{{ function end_function($cdata)
trim($cdata) . '</b></code>',
// {{{ function start_graphic($attributes)
'<img alt="%s" border="0" src="%s"%s%s/>',
isset ($attributes['srccredit']) ? $attributes['srccredit'] : '',
isset ($attributes['fileref']) ? $attributes['fileref'] : '',
isset ($attributes['width']) ? ' width="' . $attributes['width'] . '"' : '',
isset ($attributes['height']) ? ' height="' . $attributes['height'] . '"' : ''
// {{{ function end_graphic($cdata)
// {{{ function start_itemizedlist($attributes)
// {{{ function end_itemizedlist($cdata)
// {{{ function start_listitem($attributes)
// {{{ function end_listitem($cdata)
// {{{ function start_orderedlist($attributes)
// {{{ function end_orderedlist($cdata)
// {{{ function start_para($attributes)
// {{{ function end_para($cdata)
// {{{ function start_programlisting($attributes)
$this->_roles['programlisting'] = isset ($attributes['role']) ? $attributes['role'] : '';
switch ($this->_roles['programlisting']) {
// {{{ function end_programlisting($cdata)
switch ($this->_roles['programlisting']) {
$this->_roles['programlisting'] = '';
// {{{ function start_section($attributes)
$id = $this->_startSection (
isset ($attributes['id']) ? $attributes['id'] : ''
return '<div class="section">' . $id;
// {{{ function end_section($cdata)
$this->_endSection ('section');
return $cdata . '</div>';
// {{{ function start_surname($attributes)
// {{{ function end_surname($cdata)
// {{{ function start_title($attributes)
switch ($this->_context[sizeof($this->_context)-1 ]) {
return '<h2 class="title">' . $this->_currentSectionNumber . '. ';
return '<h3 class="title">Example ' . $this->_currentExampleNumber;
return '<h3 class="title">Figure ' . $this->_currentFigureNumber;
// {{{ function end_title($cdata)
if (!empty ($this->_ids[sizeof($this->_ids)-1 ])) {
switch ($this->_context[sizeof($this->_context)-1 ]) {
// {{{ function start_ulink($attributes)
return '<a href="' . $attributes['url'] . '">';
// {{{ function end_ulink($cdata)
// {{{ function start_xref($attributes)
if ($this->_secondPass) {
isset ($attributes['linkend']) ? $attributes['linkend'] : '',
isset ($this->_xref[$attributes['linkend']]) ? $this->_xref[$attributes['linkend']] : ''
XML_Util ::attributesToString ($attributes)
// {{{ function end_xref($cdata)
if (!$this->_secondPass) {
$cdata = $cdata . '</xref>';
// {{{ function _startDocument($type, $attributes)
function _startDocument ($type, $attributes) {
if (!$this->_secondPass) {
$id = $this->_startSection (
isset ($attributes['id']) ? $attributes['id'] : ''
'<html><head><title>%s: %s</title><body><h1 class="title">%s: %s</h1>',
// {{{ function _endDocument($type, $cdata)
function _endDocument ($type, $cdata) {
if (!$this->_secondPass) {
$this->_endSection ($type);
$this->_secondPass = TRUE;
$cdata = $cdata . '</body></html>';
// {{{ function _startSection($type, $id)
function _startSection ($type, $id) {
$this->_currentSectionNumber = '';
if (!isset ($this->_sections[$type]['open'])) {
$this->_sections[$type]['open'] = 1;
$this->_sections[$type]['open']++;
if (!isset ($this->_sections[$type]['id'][$this->_sections[$type]['open']])) {
$this->_sections[$type]['id'][$this->_sections[$type]['open']] = 1;
$this->_sections[$type]['id'][$this->_sections[$type]['open']]++;
for ($i = 1; $i <= $this->_sections[$type]['open']; $i++ ) {
if (!empty ($this->_currentSectionNumber)) {
$this->_currentSectionNumber .= '.';
$this->_currentSectionNumber .= $this->_sections[$type]['id'][$i];
if (!isset ($this->_examples[$this->_currentSectionNumber])) {
$this->_examples[$this->_currentSectionNumber] = 1;
$this->_examples[$this->_currentSectionNumber]++;
$this->_currentExampleNumber =
$this->_currentSectionNumber . '.' . $this->_examples[$this->_currentSectionNumber];
if (!isset ($this->_figures[$this->_currentFigureNumber])) {
$this->_figures[$this->_currentSectionNumber] = 1;
$this->_figures[$this->_currentSectionNumber]++;
$this->_currentFigureNumber =
$this->_currentSectionNumber . '.' . $this->_figures[$this->_currentSectionNumber];
$id = '<a id="' . $id . '" />';
// {{{ function _endSection($type)
function _endSection ($type) {
$this->_sections[$type]['open']--;
* vim600: et sw=2 ts=2 fdm=marker
Documentation generated on Mon, 11 Mar 2019 15:48:09 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|