HTML 5

Rendu HTML 5. plugin_html5.zip

Change log

09/01/2010

  • Première version

Source

renderer.php:

<?php
 
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
 
require_once DOKU_INC . 'inc/parser/xhtml.php';
 
/**
 * The Renderer
 */
class renderer_plugin_html5 extends Doku_Renderer_xhtml
{
    /**
     * Get the informations about the plugin
     *
     * @return      The informations
     */
    function getInfo()
    {
        return array(
            'author' => 'neolao',
            'email'  => 'neo@neolao.com',
            'date'   => '2010-01-09',
            'name'   => 'HTML5',
            'desc'   => 'Plugin to add HTML5 Renderer.',
            'url'    => '',
        );
    }
 
    /**
     * Get the format name
     *
     * @return      The format name
     */
    function getFormat()
    {
        return 'html5';
    }
 
    /**
     * Indicate that the plugin can render the specified format
     *
     * @param   string  $format     The format
     * @return  bool                true if the plugin can render the format, false otherwise
     */
    function canRender( $format )
    {
        return ( $format == 'xhtml' );
    }
 
    /**
     *
     */
    function document_end()
    {
        // Close section
        if( $this->lastlevel > 1 )
        {
            $this->doc .= str_repeat( DOKU_LF.'</section>' , $this->lastlevel -1 );
        }
 
        parent::document_end();
    }
 
 
    /**
     * Print a header
     *
     * @param   string  $text       The header content
     * @param   int     $level      The header level
     * @param   ???     $pos        ???
     */
    function header( $text, $level, $pos )
    {
        if( !$text ) return; //skip empty headlines
 
        $hid = $this->_headerToLink( $text, true );
 
        // Only add items within configured levels
        $this->toc_additem( $hid, $text, $level );
 
        // Adjust $node to reflect hierarchy of levels
        $this->node[$level-1]++;
        if ($level < $this->lastlevel) {
            for ($i = 0; $i < $this->lastlevel-$level; $i++) {
                $this->node[$this->lastlevel-$i-1] = 0;
            }
        }
        $lastLevel = $this->lastlevel;
        $this->lastlevel = $level;
 
        // Close section
        if( $lastLevel >= $level )
        {
            $this->doc .= str_repeat( DOKU_LF.'</section>' , $lastLevel - $level + 1 );
        }
 
        // Open section
        if( $level > 1 )
        {
            $this->doc .= DOKU_LF.'<section>';
        }
 
        // Write the header
        $this->doc .= DOKU_LF.'<h1><a name="'.$hid.'" id="'.$hid.'">';
        $this->doc .= $this->_xmlEntities( $text );
        $this->doc .= '</a></h1>'.DOKU_LF;
    }
 
    /**
     * Section edit marker is replaced by an edit button when
     * the page is editable. Replacement done in 'inc/html.php#html_secedit'
     */
    function section_edit( $start, $end, $level, $name )
    {
    }
 
    /**
     * Open a section
     *
     * @param   int     $level      The section level
     */
    function section_open( $level )
    {
    }
 
    /**
     * Close a section
     */
    function section_close()
    {
    }
 
    /**
     *Open list content
     */
    function listcontent_open() {
    }
 
    /**
     * Close list content
     */
    function listcontent_close() {
    }
 
    /**
     * Add a smiley
     */
    function smiley($smiley) {
        if ( array_key_exists($smiley, $this->smileys) ) {
            $title = $this->_xmlEntities($this->smileys[$smiley]);
            $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley].
                '" class="smiley" alt="'.
                    $this->_xmlEntities($smiley).'" />';
        } else {
            $this->doc .= $this->_xmlEntities($smiley);
        }
    }
 
 
 
}