-
Notifications
You must be signed in to change notification settings - Fork 9
/
syntax.php
173 lines (142 loc) · 6.83 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/**
* Add Note capability to DokuWiki
*
* <note>This is note</note>
* <note classic>This is note</note>
* <note important>This is an important note</note>
* <note warning>This is a big warning</note>
* <note tip>This is a tip</note>
*
* Initially written by:
* @author Olivier Cortes <[email protected]>
* @license GNU GPL v.2
*
* See for more information the bundled README.rdoc file.
*/
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');
class syntax_plugin_note extends DokuWiki_Syntax_Plugin {
var $notes = array(
'noteimportant' => array('important', 'importante'),
'notewarning' => array('warning','bloquante','critique'),
'notetip' => array('tip','tuyau','idée'),
'noteclassic' => array('','classic','classique')
);
var $default = 'noteclassic';
function getInfo() {
return confToHash(dirname(__FILE__).'/INFO.txt');
}
function getType(){ return 'container'; }
function getPType(){ return 'normal'; }
function getAllowedTypes() {
return array('container','substition','protected','disabled','formatting','paragraphs');
}
function getSort(){ return 195; }
// override default accepts() method to allow nesting
// - ie, to get the plugin accepts its own entry syntax
function accepts($mode) {
if ($mode == substr(get_class($this), 7)) return true;
return parent::accepts($mode);
}
function connectTo($mode) {
$this->Lexer->addEntryPattern('<note.*?>(?=.*?</note>)',$mode,'plugin_note');
}
function postConnect() {
$this->Lexer->addExitPattern('</note>','plugin_note');
}
function handle($match, $state, $pos, &$handler) {
switch ($state) {
case DOKU_LEXER_ENTER :
$note = strtolower(trim(substr($match,5,-1)));
foreach( $this->notes as $class => $names ) {
if (in_array($note, $names))
return array($state, $class);
}
return array($state, $this->default);
case DOKU_LEXER_UNMATCHED :
return array($state, $match);
default:
return array($state);
} // close switch
}
function render($mode, &$renderer, $indata) {
if($mode == 'xhtml') {
list($state, $data) = $indata;
switch ($state) {
case DOKU_LEXER_ENTER :
$renderer->doc .= '</p><div class="'.$data.'">';
break;
case DOKU_LEXER_UNMATCHED :
$renderer->doc .= $renderer->_xmlEntities($data);
break;
case DOKU_LEXER_EXIT :
$renderer->doc .= "\n</div><p>";
break;
} // close switch
return true;
} elseif ($mode == 'odt') {
list($state, $data) = $indata;
switch ($state) {
case DOKU_LEXER_ENTER :
$type = substr($data, 4);
if ($type == "classic") {
$type = "note"; // the icon for classic notes is named note.png
}
$colors = array("note"=>"#eeffff", "warning"=>"#ffdddd", "important"=>"#ffffcc", "tip"=>"#ddffdd");
$renderer->autostyles["pluginnote"] = '
<style:style style:name="pluginnote" style:family="table">
<style:table-properties style:width="15cm" table:align="center" style:shadow="#808080 0.18cm 0.18cm"/>
</style:style>';
$renderer->autostyles["pluginnote.A"] = '
<style:style style:name="pluginnote.A" style:family="table-column">
<style:table-column-properties style:column-width="1.5cm"/>
</style:style>';
$renderer->autostyles["pluginnote.B"] = '
<style:style style:name="pluginnote.B" style:family="table-column">
<style:table-column-properties style:column-width="13.5cm"/>
</style:style>';
$renderer->autostyles["pluginnote".$type.".A1"] = '
<style:style style:name="pluginnote'.$type.'.A1" style:family="table-cell">
<style:table-cell-properties style:vertical-align="middle" fo:padding="0.1cm" fo:border-left="0.002cm solid #000000" fo:border-right="none" fo:border-top="0.002cm solid #000000" fo:border-bottom="0.002cm solid #000000" fo:background-color="'.$colors[$type].'"/>
</style:style>';
$renderer->autostyles["pluginnote".$type.".B1"] = '
<style:style style:name="pluginnote'.$type.'.B1" style:family="table-cell">
<style:table-cell-properties style:vertical-align="middle" fo:padding="0.3cm" fo:border-left="none" fo:border-right="0.002cm solid #000000" fo:border-top="0.002cm solid #000000" fo:border-bottom="0.002cm solid #000000" fo:background-color="'.$colors[$type].'"/>
</style:style>';
// Content
$renderer->p_close();
$renderer->doc .= '<table:table table:name="" table:style-name="pluginnote">';
$renderer->doc .= '<table:table-column table:style-name="pluginnote.A"/>';
$renderer->doc .= '<table:table-column table:style-name="pluginnote.B"/>';
$renderer->doc .= '<table:table-row>';
$renderer->doc .= '<table:table-cell table:style-name="pluginnote'.$type.'.A1" office:value-type="string">';
// Don't use p_open, as it's not the same style-name
$renderer->doc .= '<text:p text:style-name="Table_20_Contents">';
$src = DOKU_PLUGIN."note/images/".$type.".png";
$renderer->_odtAddImage($src);
$renderer->doc .= '</text:p>';
$renderer->doc .= '</table:table-cell>';
$renderer->doc .= '<table:table-cell table:style-name="pluginnote'.$type.'.B1" office:value-type="string">';
$renderer->p_open();
break;
case DOKU_LEXER_UNMATCHED :
$renderer->cdata($data);
break;
case DOKU_LEXER_EXIT :
$renderer->p_close();
$renderer->doc .= '</table:table-cell>';
$renderer->doc .= '</table:table-row>';
$renderer->doc .= '</table:table>';
$renderer->p_open();
break;
} // close switch
return true;
}
// unsupported $mode
return false;
} // close render function
} // syntax_plugin_note class
//Setup VIM: ex: et ts=4 enc=utf-8 :
?>