for licensing details. // Copyright (c) 2011 Samuel G. D. Williams. if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once DOKU_PLUGIN.'syntax.php'; class syntax_plugin_jquerysyntax_code extends DokuWiki_Syntax_Plugin { var $syntax = ""; function getInfo() { return array( 'author' => 'Samuel Williams', 'email' => 'samuel.williams@oriontransfer.co.nz', 'date' => '2012-06-01', 'name' => 'jQuery.Syntax', 'desc' => "Extreme Client-side Syntax Highlighting. Replaces DokuWiki's handler.", 'url' => 'http://www.oriontransfer.co.nz/software/jquery-syntax', ); } function getType() { return 'protected'; } function getPType() { return 'block'; } // must return a number lower than returned by native 'code' mode (200) function getSort() { return 100; } // Connect pattern to lexer function connectTo($mode) { $this->Lexer->addEntryPattern('.*?)', $mode, 'plugin_jquerysyntax_code'); } function postConnect() { $this->Lexer->addExitPattern('', 'plugin_jquerysyntax_code'); } // Process DokuWiki Source function handle($match, $state, $pos, &$handler) { switch ($state) { case DOKU_LEXER_ENTER: $this->syntax = substr($match, 1); return false; case DOKU_LEXER_UNMATCHED: // will include everything from // e.g. ... [lang] [|title] > [content] list($attr, $content) = preg_split('/>/u',$match,2); list($lang, $title) = preg_split('/\|/u',$attr,2); return array($this->syntax, trim($lang), trim($title), $content); } return false; } // Create output HTML function render($mode, &$renderer, $data) { if($mode == 'xhtml') { if (count($data) == 4) { list($syntax, $lang, $title, $content) = $data; if ($title) $renderer->doc .= "

".$renderer->_xmlEntities($title)."

"; if ($syntax == 'code') $renderer->doc .= "
".$renderer->_xmlEntities($content)."
"; else $renderer->file($content); if ($title) $renderer->doc .= "
"; } return true; } return false; } }