1<?php
2/**
3 * flowchartjs plugin: draw flowcart based on flowcart.js
4 *
5 * Syntax: <flowchartjs style>...</flowchartjs> - will draw a flowchart
6 *
7 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author     Hua Gao <ghbore@gmail.com>
9 */
10
11if(!defined('DOKU_INC')) die();
12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13require_once(DOKU_PLUGIN.'syntax.php');
14
15/**
16 * All DokuWiki plugins to extend the parser/rendering mechanism
17 * need to inherit from this class
18 */
19class syntax_plugin_flowchartjs extends DokuWiki_Syntax_Plugin {
20
21	function getType(){ return 'protected'; }
22	function getPType(){ return 'block'; }
23	function getSort(){ return 999; }
24	function connectTo($mode) {
25    	$this->Lexer->addEntryPattern('<flowchartjs.*?>(?=.*?</flowchartjs>)', $mode, 'plugin_flowchartjs');
26	}
27	function postConnect() {
28		$this->Lexer->addExitPattern('</flowchartjs>', 'plugin_flowchartjs');
29	}
30	function handle($match, $state, $pos, Doku_Handler $handler){
31		switch ($state) {
32			case DOKU_LEXER_ENTER :
33				$style = trim(substr($match, 12, -1));
34				return array($state, $style);
35			case DOKU_LEXER_UNMATCHED :
36		  		return array($state, $match);
37			case DOKU_LEXER_EXIT :
38				return array($state, '');
39		}
40	}
41	function render($mode, Doku_Renderer $renderer, $data) {
42		if($mode == 'xhtml'){
43			list($state, $match) = $data;
44			switch ($state){
45				case DOKU_LEXER_ENTER:
46					$renderer->doc .= "<pre class='flowchartjs $match'>";
47					break;
48				case DOKU_LEXER_UNMATCHED:
49					$renderer->doc .= $match;
50					break;
51				case DOKU_LEXER_EXIT:
52					$renderer->doc .= "</pre>";
53					break;
54			}
55			return true;
56		}
57		return false;
58	}
59}
60
61//Setup VIM: ex: et ts=4 :
62