<?php
/**
 * DokuWiki Plugin floatdiv (Syntax Component)
 *
 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
 * @author  Tinkerghost <geek@rentedgeek.com>
 */

// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();

if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');

require_once DOKU_PLUGIN.'syntax.php';

class syntax_plugin_floatdiv_floathead extends DokuWiki_Syntax_Plugin {
    public function getType() {
        return 'formatting';
    }

    public function getPType() {
        return 'block';
    }

    public function getSort() {
        return 32;
    }


    public function connectTo($mode) {
        $this->Lexer->addSpecialPattern('~\$+ .+? \$+~',$mode,'plugin_floatdiv_floathead');
//        $this->Lexer->addEntryPattern('<FIXME>',$mode,'plugin_floatdiv_floathead');
    }

//    public function postConnect() {
//        $this->Lexer->addExitPattern('</FIXME>','plugin_floatdiv_floathead');
//    }

    public function handle($match, $state, $pos, &$handler){
		preg_match('/^~(\$+) (.+)? (\$+)~/',$match,$matches);
        return array(strlen($matches[1]),$matches[2]);
    }

    public function render($mode, &$renderer, $data) {
        if($mode != 'xhtml') return false;
		list($size,$match) = $data;
		if ($size > 6){$size = 6;}
		$renderer->doc .= "<div class='floathead$size'>".
			$renderer->_xmlEntities($match)."</div>";
        return true;
    }
}

// vim:ts=4:sw=4:et:
