2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6
* This BB renderer produces BB code, ready to be pasted in bulletin boards and
7
* other applications that accept BB code. Based on the HTML renderer by Andrey Demenev.
9
* LICENSE: This source file is subject to version 3.0 of the PHP license
10
* that is available through the world-wide-web at the following URI:
11
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
12
* the PHP License and are unable to obtain it through the web, please
13
* send a note to license@php.net so we can mail you a copy immediately.
16
* @package Text_Highlighter
17
* @author Stoyan Stefanov <ssttoo@gmail.com>
18
* @copyright 2005 Stoyan Stefanov
19
* @license http://www.php.net/license/3_0.txt PHP License
20
* @version CVS: $Id: BB.php,v 1.1 2007/06/03 02:37:08 ssttoo Exp $
21
* @link http://pear.php.net/package/Text_Highlighter
28
require_once dirname(__FILE__).'/../Renderer.php';
31
* BB code renderer, based on Andrey Demenev's HTML renderer.
33
* Elements of $options argument of constructor (each being optional):
35
* - 'numbers' - Line numbering TRUE or FALSE
36
* - 'tabsize' - Tab size, default is 4
37
* - 'bb_tags' - An array containing three BB tags, see below
38
* - 'tag_brackets' - An array that conains opening and closing tags, [ and ]
39
* - 'colors' - An array with all the colors to be used for highlighting
41
* The default BB tags are:
42
* - 'color' => 'color'
44
* - 'list_item' => '*'
46
* The default colors for the highlighter are:
47
* - 'default' => 'Black',
49
* - 'brackets' => 'Olive',
50
* - 'comment' => 'Orange',
51
* - 'mlcomment' => 'Orange',
52
* - 'quotes' => 'Darkred',
53
* - 'string' => 'Red',
54
* - 'identifier' => 'Blue',
55
* - 'builtin' => 'Teal',
56
* - 'reserved' => 'Green',
57
* - 'inlinedoc' => 'Blue',
58
* - 'var' => 'Darkblue',
60
* - 'special' => 'Navy',
61
* - 'number' => 'Maroon',
62
* - 'inlinetags' => 'Blue',
65
* @author Stoyan Stefanov <ssttoo@gmail.com>
67
* @package Text_Highlighter
68
* @copyright 20045 Stoyan Stefanov
69
* @license http://www.php.net/license/3_0.txt PHP License
70
* @version Release: 0.5.0
71
* @link http://pear.php.net/package/Text_Highlighter
74
class Text_Highlighter_Renderer_BB extends Text_Highlighter_Renderer_Array
82
* Line numbering - will use the specified BB tag for listings
86
var $_numbers = false;
93
var $_bb_tags = array (
101
* BB brackets - [ and ]
105
var $_tag_brackets = array ('start' => '[', 'end' => ']');
112
var $_colors = array(
113
'default' => 'Black',
115
'brackets' => 'Olive',
116
'comment' => 'Orange',
117
'mlcomment' => 'Orange',
118
'quotes' => 'Darkred',
120
'identifier' => 'Blue',
122
'reserved' => 'Green',
123
'inlinedoc' => 'Blue',
127
'number' => 'Maroon',
128
'inlinetags' => 'Blue',
134
* Resets renderer state
139
* Descendents of Text_Highlighter call this method from the constructor,
140
* passing $options they get as parameter.
145
if (isset($this->_options['numbers'])) {
146
$this->_numbers = $this->_options['numbers'];
148
if (isset($this->_options['bb_tags'])) {
149
$this->_bb_tags = array_merge($this->_bb_tags, $this->_options['bb_tags']);
151
if (isset($this->_options['tag_brackets'])) {
152
$this->_tag_brackets = array_merge($this->_tag_brackets, $this->_options['tag_brackets']);
154
if (isset($this->_options['colors'])) {
155
$this->_colors = array_merge($this->_colors, $this->_options['colors']);
161
* Signals that no more tokens are available
170
// get parent's output
172
$output = parent::getOutput();
176
$color_start = $this->_tag_brackets['start'] . $this->_bb_tags['color'] . '=%s' . $this->_tag_brackets['end'];
177
$color_end = $this->_tag_brackets['start'] . '/' . $this->_bb_tags['color'] . $this->_tag_brackets['end'];
179
// loop through each class=>content pair
180
foreach ($output AS $token) {
182
if ($this->_enumerated) {
184
$content = $token[1];
188
$content = $token[$key];
191
$iswhitespace = ctype_space($content);
192
if (!$iswhitespace && !empty($this->_colors[$class])) {
193
$bb_output .= sprintf($color_start, $this->_colors[$class]);
194
$bb_output .= $content;
195
$bb_output .= $color_end;
197
$bb_output .= $content;
201
if ($this->_numbers) {
203
$item_tag = $this->_tag_brackets['start'] .
204
$this->_bb_tags['list_item'] .
205
$this->_tag_brackets['end'];
206
$this->_output = $item_tag . str_replace("\n", "\n". $item_tag .' ', $bb_output);
207
$this->_output = $this->_tag_brackets['start'] .
208
$this->_bb_tags['list'] .
209
$this->_tag_brackets['end'] .
211
$this->_tag_brackets['start'] .
213
$this->_bb_tags['list'] .
214
$this->_tag_brackets['end']
217
$this->_output = $this->_tag_brackets['start'] .
218
$this->_bb_tags['code'] .
219
$this->_tag_brackets['end'] .
221
$this->_tag_brackets['start'] .
223
$this->_bb_tags['code'] .
224
$this->_tag_brackets['end'];
234
* c-hanging-comment-ender-p: nil
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6
* This BB renderer produces BB code, ready to be pasted in bulletin boards and
7
* other applications that accept BB code. Based on the HTML renderer by Andrey Demenev.
9
* LICENSE: This source file is subject to version 3.0 of the PHP license
10
* that is available through the world-wide-web at the following URI:
11
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
12
* the PHP License and are unable to obtain it through the web, please
13
* send a note to license@php.net so we can mail you a copy immediately.
16
* @package Text_Highlighter
17
* @author Stoyan Stefanov <ssttoo@gmail.com>
18
* @copyright 2005 Stoyan Stefanov
19
* @license http://www.php.net/license/3_0.txt PHP License
20
* @version CVS: $Id: BB.php,v 1.1 2007/06/03 02:37:08 ssttoo Exp $
21
* @link http://pear.php.net/package/Text_Highlighter
28
require_once dirname(__FILE__).'/../Renderer.php';
31
* BB code renderer, based on Andrey Demenev's HTML renderer.
33
* Elements of $options argument of constructor (each being optional):
35
* - 'numbers' - Line numbering TRUE or FALSE
36
* - 'tabsize' - Tab size, default is 4
37
* - 'bb_tags' - An array containing three BB tags, see below
38
* - 'tag_brackets' - An array that conains opening and closing tags, [ and ]
39
* - 'colors' - An array with all the colors to be used for highlighting
41
* The default BB tags are:
42
* - 'color' => 'color'
44
* - 'list_item' => '*'
46
* The default colors for the highlighter are:
47
* - 'default' => 'Black',
49
* - 'brackets' => 'Olive',
50
* - 'comment' => 'Orange',
51
* - 'mlcomment' => 'Orange',
52
* - 'quotes' => 'Darkred',
53
* - 'string' => 'Red',
54
* - 'identifier' => 'Blue',
55
* - 'builtin' => 'Teal',
56
* - 'reserved' => 'Green',
57
* - 'inlinedoc' => 'Blue',
58
* - 'var' => 'Darkblue',
60
* - 'special' => 'Navy',
61
* - 'number' => 'Maroon',
62
* - 'inlinetags' => 'Blue',
65
* @author Stoyan Stefanov <ssttoo@gmail.com>
67
* @package Text_Highlighter
68
* @copyright 20045 Stoyan Stefanov
69
* @license http://www.php.net/license/3_0.txt PHP License
70
* @version Release: 0.5.0
71
* @link http://pear.php.net/package/Text_Highlighter
74
class Text_Highlighter_Renderer_BB extends Text_Highlighter_Renderer_Array
82
* Line numbering - will use the specified BB tag for listings
86
var $_numbers = false;
93
var $_bb_tags = array (
101
* BB brackets - [ and ]
105
var $_tag_brackets = array ('start' => '[', 'end' => ']');
112
var $_colors = array(
113
'default' => 'Black',
115
'brackets' => 'Olive',
116
'comment' => 'Orange',
117
'mlcomment' => 'Orange',
118
'quotes' => 'Darkred',
120
'identifier' => 'Blue',
122
'reserved' => 'Green',
123
'inlinedoc' => 'Blue',
127
'number' => 'Maroon',
128
'inlinetags' => 'Blue',
134
* Resets renderer state
139
* Descendents of Text_Highlighter call this method from the constructor,
140
* passing $options they get as parameter.
145
if (isset($this->_options['numbers'])) {
146
$this->_numbers = $this->_options['numbers'];
148
if (isset($this->_options['bb_tags'])) {
149
$this->_bb_tags = array_merge($this->_bb_tags, $this->_options['bb_tags']);
151
if (isset($this->_options['tag_brackets'])) {
152
$this->_tag_brackets = array_merge($this->_tag_brackets, $this->_options['tag_brackets']);
154
if (isset($this->_options['colors'])) {
155
$this->_colors = array_merge($this->_colors, $this->_options['colors']);
161
* Signals that no more tokens are available
170
// get parent's output
172
$output = parent::getOutput();
176
$color_start = $this->_tag_brackets['start'] . $this->_bb_tags['color'] . '=%s' . $this->_tag_brackets['end'];
177
$color_end = $this->_tag_brackets['start'] . '/' . $this->_bb_tags['color'] . $this->_tag_brackets['end'];
179
// loop through each class=>content pair
180
foreach ($output AS $token) {
182
if ($this->_enumerated) {
184
$content = $token[1];
188
$content = $token[$key];
191
$iswhitespace = ctype_space($content);
192
if (!$iswhitespace && !empty($this->_colors[$class])) {
193
$bb_output .= sprintf($color_start, $this->_colors[$class]);
194
$bb_output .= $content;
195
$bb_output .= $color_end;
197
$bb_output .= $content;
201
if ($this->_numbers) {
203
$item_tag = $this->_tag_brackets['start'] .
204
$this->_bb_tags['list_item'] .
205
$this->_tag_brackets['end'];
206
$this->_output = $item_tag . str_replace("\n", "\n". $item_tag .' ', $bb_output);
207
$this->_output = $this->_tag_brackets['start'] .
208
$this->_bb_tags['list'] .
209
$this->_tag_brackets['end'] .
211
$this->_tag_brackets['start'] .
213
$this->_bb_tags['list'] .
214
$this->_tag_brackets['end']
217
$this->_output = $this->_tag_brackets['start'] .
218
$this->_bb_tags['code'] .
219
$this->_tag_brackets['end'] .
221
$this->_tag_brackets['start'] .
223
$this->_bb_tags['code'] .
224
$this->_tag_brackets['end'];
234
* c-hanging-comment-ender-p: nil
b'\\ No newline at end of file'