-
Notifications
You must be signed in to change notification settings - Fork 0
/
syntax.php
81 lines (72 loc) · 1.65 KB
/
syntax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* Adds <rtl> and <ltr> tags to syntax.
*
* @author Hamid Fadishei <[email protected]>
*/
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_dokubidi extends DokuWiki_Syntax_Plugin
{
function getType()
{
return 'formatting';
}
function getAllowedTypes()
{
return array('baseonly', 'container', 'substition', 'protected', 'disabled', 'formatting');
}
function getPType()
{
return 'normal';
}
function getSort()
{
return 500;
}
function connectTo($mode)
{
$this->Lexer->addEntryPattern('<ltr>(?=.*?</ltr>)', $mode, 'plugin_dokubidi');
$this->Lexer->addEntryPattern('<rtl>(?=.*?</rtl>)', $mode, 'plugin_dokubidi');
}
function postConnect()
{
$this->Lexer->addExitPattern('</ltr>', 'plugin_dokubidi');
$this->Lexer->addExitPattern('</rtl>', 'plugin_dokubidi');
}
function handle($match, $state, $pos, &$handler)
{
switch ($state)
{
case DOKU_LEXER_ENTER:
return array($state, substr($match, 1, 3));
case DOKU_LEXER_UNMATCHED:
return array($state, $match);
case DOKU_LEXER_EXIT:
return array($state, "");
}
return array();
}
function render($mode, &$renderer, $data)
{
if($mode == 'xhtml')
{
list($state, $match) = $data;
switch ($state)
{
case DOKU_LEXER_ENTER:
$renderer->doc .= "<div style='direction:".$match.";'>";
break;
case DOKU_LEXER_UNMATCHED:
$renderer->doc .= $renderer->_xmlEntities($match);
break;
case DOKU_LEXER_EXIT:
$renderer->doc .= "</div>";
break;
}
return true;
}
return false;
}
}