1: <?php
2: /**
3: * Renders Wiki page headers to restructured text.
4: *
5: * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
6: *
7: * See the enclosed file COPYING for license information (GPLv2). If
8: * you did not receive this file, see
9: * http://www.horde.org/licenses/gpl
10: *
11: * PHP version 5
12: *
13: * @category Horde
14: * @package Wicked
15: * @author Gunnar Wrobel <wrobel@pardus.de>
16: * @link http://www.horde.org/apps/wicked
17: * @license http://www.horde.org/licenses/gpl GNU General Public License, version 2
18: */
19:
20: /**
21: * Renders Wiki page headers to restructured text.
22: *
23: * @category Horde
24: * @package Wicked
25: * @author Gunnar Wrobel <wrobel@pardus.de>
26: * @link http://www.horde.org/apps/wicked
27: * @license http://www.horde.org/licenses/gpl GNU General Public License, version 2
28: */
29: class Text_Wiki_Render_Rst_Heading2 extends Text_Wiki_Render
30: {
31: /**
32: * The start options.
33: *
34: * @var array
35: */
36: private $_previous;
37:
38: /**
39: * Render the header.
40: *
41: * @param array $options The rendering options.
42: *
43: * @return string The output string.
44: */
45: public function token($options)
46: {
47: // get nice variable names (type, level)
48: extract($options);
49:
50: if ($type == 'start') {
51: $length = strlen($text);
52: switch ($level) {
53: case '1':
54: $overline = '=';
55: $underline = '=';
56: $length += 2;
57: break;
58: case '2':
59: $overline = '-';
60: $underline = '-';
61: $length += 2;
62: break;
63: case '3':
64: $overline = null;
65: $underline = '=';
66: break;
67: case '4':
68: $overline = null;
69: $underline = '*';
70: break;
71: case '5':
72: $overline = null;
73: $underline = '-';
74: break;
75: case '6':
76: $overline = null;
77: $underline = '`';
78: break;
79: }
80: $output = '';
81: if ($overline !== null) {
82: $output .= str_repeat($overline, $length) . "\n ";
83: }
84: $previous = $options;
85: $previous['length'] = $length;
86: $previous['underline'] = $underline;
87: $this->_previous[] = $previous;
88: return $output;
89: }
90:
91: if ($type == 'end') {
92: $previous = array_pop($this->_previous);
93: if ($level != $previous['level']) {
94: return sprintf(
95: 'UNEXPECTED HEADER LEVEL: %s [expected %s]',
96: $level,
97: $previous['level']
98: );
99: }
100: return "\n" . str_repeat($previous['underline'], $previous['length']) . "\n\n";
101: }
102: }
103: }
104: