1<?php
2
3	if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
4	if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
5	require_once(DOKU_PLUGIN.'syntax.php');
6
7
8	class syntax_plugin_skipentity extends DokuWiki_Syntax_Plugin {
9
10
11        function getType(){ return 'formatting'; }
12		function getAllowedTypes() {
13            global $PARSER_MODES;
14            $excludes = explode(',',$this->getConf('xcl_formats'));
15            foreach($excludes AS $del_val) {
16               $this->array_val_delete($PARSER_MODES['formatting'],trim($del_val));
17            }
18            if($this->getConf('allow_formats')) {
19                return array('formatting');
20            }
21			return array();
22		}
23		function getSort(){ return 25; }
24
25		function connectTo($mode) {
26        	$this->Lexer->addEntryPattern('```?(?=.*?```?)',$mode,'plugin_skipentity');
27		}
28
29		function postConnect() {
30            $this->Lexer->addExitPattern('```?','plugin_skipentity');
31		}
32
33		function __construct() {	}
34
35		function handle($match, $state, $pos,  Doku_Handler $handler) {
36 			switch ($state) {
37				case DOKU_LEXER_ENTER :
38				   return array($state, trim($match));
39
40				case DOKU_LEXER_UNMATCHED :
41				return array($state, $match);
42
43				case DOKU_LEXER_EXIT :
44				return array($state,'');
45
46				default:
47				return array($state,$match);
48			}
49		}
50
51		function render($mode,  Doku_Renderer  $renderer, $data) {
52			global $INFO;
53
54			if($mode == 'xhtml'){
55
56				list($state, $match) = $data;
57
58				switch ($state) {
59					case DOKU_LEXER_ENTER :
60                    if($match == '``') {
61                              $renderer->doc .= '<code>';
62                       }
63                      else {
64                         $renderer->doc .= '<code class="skipentity">';
65                      }
66                      break;
67
68					case DOKU_LEXER_UNMATCHED :
69                        $match = $renderer->_xmlEntities($match);
70                        $match = str_replace("\n","<br>", $match);
71                        if(strpos($match,'  ') !== false) {
72                            $match = preg_replace("/\s/m","&nbsp;",$match);
73                        }
74                        $renderer->doc .= $match;
75					break;
76					case DOKU_LEXER_EXIT :
77				    $renderer->doc .= "</code>";
78				    break;
79				}
80				return true;
81
82			}
83
84			return false;
85		}
86
87    function array_val_delete(&$ar,$del_val){
88        if (($key = array_search($del_val, $ar)) !== false) {
89        unset($ar[$key]);
90    }
91   }
92 }
93
94
95?>
96