forked from dokufreaks/plugin-bbcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmallcaps.php
More file actions
103 lines (92 loc) · 3.57 KB
/
smallcaps.php
File metadata and controls
103 lines (92 loc) · 3.57 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* @file bbcode/syntax/smallcaps.php
* @brief Small-caps formatting support for BBCode Plugin
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Luis Machuca Bezzaza <luis.machuca@gulix.cl>
*
* This file adds smallcaps (font-variant:small-caps) support to the
* BBCode plugin. It also adds preliminary support for the ODT Renderer.
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_bbcode_smallcaps extends DokuWiki_Syntax_Plugin {
function getType() { return 'formatting'; }
function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }
function getSort() { return 105; }
function connectTo($mode) { $this->Lexer->addEntryPattern('\[c\](?=.*?\x5B/c\x5D)',$mode,'plugin_bbcode_smallcaps'); }
function postConnect() { $this->Lexer->addExitPattern('\[/c\]','plugin_bbcode_smallcaps'); }
/**
* Handle the match
*/
function handle($match, $state, $pos, &$handler) {
switch ($state) {
case DOKU_LEXER_ENTER :
$match = substr($match, 2,-2);
return array($state, $match);
case DOKU_LEXER_UNMATCHED :
return array($state, $match);
case DOKU_LEXER_EXIT :
return array($state, '');
}
return array();
}
/**
* Create output
*/
function render($mode, &$renderer, $data) {
list($state, $match) = $data;
if($mode == 'xhtml') {
switch ($state) {
case DOKU_LEXER_ENTER :
// the class is not necessary, but it's there in case it's needed later
$renderer->doc .= '<span class="bbcode_smallcaps" style="font-variant: small-caps;">';
break;
case DOKU_LEXER_UNMATCHED :
$renderer->doc .= $renderer->_xmlEntities($match);
break;
case DOKU_LEXER_EXIT :
$renderer->doc .= '</span>';
break;
}
return true;
}
else if ($mode == 'odt') {
static $style= false;
if ($style === false) {
$renderer->autostyles["smallcaps"] = $this->ODT_autostyle('BBCode_smallcaps');
$style= true;
}
switch ($state) {
case DOKU_LEXER_ENTER :
// styling via the created auto-style, pretty straightforward...
$renderer->doc .= '<text:span text:style-name="BBCode_smallcaps">';
break;
case DOKU_LEXER_UNMATCHED :
$renderer->doc .= $renderer->_xmlEntities($match);
break;
case DOKU_LEXER_EXIT :
$renderer->doc .= '</text:span>';
break;
}
return true;
}
// explicit support for text renderer is not needed
return false;
}
/**
* create an autostyle for small-caps with the name given.
*/
private function ODT_autostyle ($aname) {
static $autostyle= '
<style:style style:name="$1" style:display-name="BBCode smallcaps" style:family="text">
<style:text-properties fo:font-variant="small-caps"/>
</style:style>';
return str_replace('$1',$aname, $autostyle);
}
}