docbook.php

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 1,110 行 · 第 1/2 页

PHP
1,110
字号
<?php//// +---------------------------------------------------------------------------+// | PEAR :: XML :: Transformer :: DocBook Namespace Handler                   |// +---------------------------------------------------------------------------+// | Copyright (c) 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de> and |// |                         Kristian K鰄ntopp <kris@koehntopp.de>.            |// +---------------------------------------------------------------------------+// | 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.                    |// +---------------------------------------------------------------------------+//// $Id: DocBook.php,v 1.28 2004/11/19 07:18:57 sebastian Exp $//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: * *   - <artheader> *   - <article> *   - <author> *   - <book> *   - <chapter> *   - <emphasis> *   - <example> *   - <figure> *   - <filename> *   - <firstname> *   - <function> *   - <graphic> *   - <itemizedlist> *   - <listitem> *   - <orderedlist> *   - <para> *   - <programlisting> *   - <section> *   - <surname> *   - <title> *   - <ulink> *   - <xref> * * Example * * <code> * <?php * require_once 'XML/Transformer/Driver/OutputBuffer.php'; * $t = new XML_Transformer_Driver_OutputBuffer( *   array( *     'autoload' => 'DocBook' *   ) * ); * ?> * <article> *   <artheader> *     <title>An Article</title> * *     <author> *       <firstname>Sebastian</firstname> *       <surname>Bergmann</surname> *     </author> *   </artheader> * *   <section id="foo"> *     <title>Section One</title> *   </section> * *   <section id="bar"> *     <title>Section Two</title> * *     <para> *       <xref linkend="foo" /> *     </para> *   </section> * </article> * </code> * * Output * * <code> * <html> *   <head> *     <title> *       Sebastian Bergmann: An Article *     </title> *   </head> *   <body> *     <h1 class="title"> *       Sebastian Bergmann: An Article *     </h1> *     <div class="section"> *       <a id="foo"></a> *       <h2 class="title"> *         1. Section One *       </h2> *     </div> *     <div class="section"> *       <a id="bar"></a> *       <h2 class="title"> *         2. Section Two *       </h2> *       <p> *         <a href="#foo"> *           1. Section One *         </a> *       </p> *     </div> *   </body> * </html> * </code> * * @author      Sebastian Bergmann <sb@sebastian-bergmann.de> * @author      Kristian K鰄ntopp <kris@koehntopp.de> * @copyright   Copyright &copy; 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de> and Kristian K鰄ntopp <kris@koehntopp.de> * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category    XML * @package     XML_Transformer */class XML_Transformer_Namespace_DocBook extends XML_Transformer_Namespace {    // {{{ Members    /**    * @var    string    * @access public    */    var $defaultNamespacePrefix = '&MAIN';    /**    * @var    boolean    * @access public    */    var $secondPassRequired = TRUE;    /**    * @var    string    * @access private    */    var $_author = '';    /**    * @var    array    * @access private    */    var $_context = array();    /**    * @var    string    * @access private    */    var $_currentExampleNumber = '';    /**    * @var    string    * @access private    */    var $_currentFigureNumber = '';    /**    * @var    string    * @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',      'default' => '#113d73',      'html'    => '#000000',      'keyword' => '#005500',      'string'  => '#550000'    );    /**    * @var    array    * @access private    */    var $_ids = array();    /**    * @var    boolean    * @access private    */    var $_roles = array();    /**    * @var    array    * @access private    */    var $_secondPass = FALSE;    /**    * @var    array    * @access private    */    var $_sections = array();    /**    * @var    string    * @access private    */    var $_title = '';    /**    * @var    array    * @access private    */    var $_xref = '';    // }}}    // {{{ function XML_Transformer_Namespace_DocBook($parameters = array())    /**    * @param  array    * @access public    */    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)    /**    * @param  array    * @return string    * @access public    */    function start_artheader($attributes) {        if (!$this->_secondPass) {            return sprintf(              '<artheader%s>',              XML_Util::attributesToString($attributes)            );        }    }    // }}}    // {{{ function end_artheader($cdata)    /**    * @param  string    * @return string    * @access public    */    function end_artheader($cdata) {        if (!$this->_secondPass) {            $cdata = $cdata . '</artheader>';            return array(              $cdata,              FALSE            );        }    }    // }}}    // {{{ function start_article($attributes)    /**    * @param  array    * @return string    * @access public    */    function start_article($attributes) {        return $this->_startDocument('article', $attributes);    }    // }}}    // {{{ function end_article($cdata)    /**    * @param  string    * @return string    * @access public    */    function end_article($cdata) {        return $this->_endDocument('article', $cdata);    }    // }}}    // {{{ function start_author($attributes)    /**    * @param  array    * @return string    * @access public    */    function start_author($attributes) {}    // }}}    // {{{ function end_author($cdata)    /**    * @param  string    * @return string    * @access public    */    function end_author($cdata) {        $this->_author = trim(str_replace("\n", '', $cdata));    }    // }}}    // {{{ function start_book($attributes)    /**    * @param  array    * @return string    * @access public    */    function start_book($attributes) {        return $this->_startDocument('book', $attributes);    }    // }}}    // {{{ function end_book($cdata)    /**    * @param  string    * @return string    * @access public    */    function end_book($cdata) {        return $this->_endDocument('book', $cdata);    }    // }}}    // {{{ function start_chapter($attributes)    /**    * @param  array    * @return string    * @access public    */    function start_chapter($attributes) {        $id = $this->_startSection(          'chapter',          isset($attributes['id']) ? $attributes['id'] : ''        );        return '<div class="chapter">' . $id;    }    // }}}    // {{{ function end_chapter($cdata)    /**    * @param  string    * @return string    * @access public    */    function end_chapter($cdata) {        $this->_endSection('chapter');        return $cdata . '</div>';    }    // }}}    // {{{ function start_emphasis($attributes)    /**    * @param  array    * @return string    * @access public    */    function start_emphasis($attributes) {        $emphasisRole = isset($attributes['role']) ? $attributes['role'] : '';        switch($emphasisRole) {            case 'bold':            case 'strong': {                $this->_roles['emphasis'] = 'b';            }            break;            default: {                $this->_roles['emphasis'] = 'i';            }        }        return '<' . $this->_roles['emphasis'] . '>';    }    // }}}    // {{{ function end_emphasis($cdata)    /**    * @param  string    * @return string    * @access public    */    function end_emphasis($cdata) {        $cdata = sprintf(          '%s</%s>',          $cdata,          $this->_roles['emphasis']        );        $this->_roles['emphasis'] = '';        return $cdata;    }    // }}}    // {{{ function start_example($attributes)    /**    * @param  array    * @return string    * @access public    */    function start_example($attributes) {        $id = $this->_startSection(          'example',          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) {        $id = $this->_startSection(          'figure',          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)    /**    * @param  array    * @return string    * @access public    */    function start_filename($attributes) {        return '<tt>';    }    // }}}    // {{{ function end_filename($cdata)    /**    * @param  string    * @return string    * @access public    */    function end_filename($cdata) {        return trim($cdata) . '</tt>';    }    // }}}    // {{{ function start_firstname($attributes)    /**    * @param  array    * @return string    * @access public    */    function start_firstname($attributes) {}    // }}}    // {{{ function end_firstname($cdata)    /**    * @param  string    * @return string    * @access public    */    function end_firstname($cdata) {        return trim($cdata);    }    // }}}    // {{{ function start_function($attributes)    /**    * @param  array    * @return string    * @access public    */    function start_function($attributes) {        return '<code><b>';    }    // }}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?