[MANUAL] English:
[zend.git] / documentation / manual / en / module_specs / Zend_Markup-Renderers.xml
blobd93b909f73c907a7eac3389ad58fe282ea8c41bc
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!-- Reviewed: no -->
3 <sect1 id="zend.markup.renderers">
4     <title>Zend_Markup Renderers</title>
6     <para>
7         <classname>Zend_Markup</classname> is currently shipped with one renderer, the
8         <acronym>HTML</acronym> renderer.
9     </para>
11     <sect2 id="zend.markup.renderers.add">
12         <title>Adding your own markups</title>
14         <para>
15             By adding your own markups, you can add your own functionality to the
16             <classname>Zend_Markup</classname> renderers. With the markup structure, you can add
17             about any functionality you want. From simple markups, to complicated markup structures.
18             A simple example for a 'foo' markup:
19         </para>
21         <programlisting language="php"><![CDATA[
22 // Creates instance of Zend_Markup_Renderer_Html,
23 // with Zend_Markup_Parser_BbCode as its parser
24 $bbcode = Zend_Markup::factory('Bbcode');
26 // this will create a simple 'foo' markup
27 // The first parameter defines the markup's name.
28 // The second parameter takes an integer that defines the markups type.
29 // The third parameter is an array that defines other things about a
30 // markup, like the markup's group, and (in this case) a start and end markup.
31 $bbcode->addMarkup(
32     'foo',
33     Zend_Markup_Renderer_RendererAbstract::TYPE_REPLACE,
34     array(
35         'start' => '-bar-',
36         'end'   => '-baz-',
37         'group' => 'inline'
38     )
41 // now, this will output: 'my -bar-markup-baz-'
42 echo $bbcode->render('my [foo]markup[/foo]');
43 ]]></programlisting>
45         <para>
46             Please note that creating your own markups only makes sense when your parser also
47             supports it with a markup structure. Currently, only BBCode supports this. Textile
48             doesn't have support for custom markups.
49         </para>
51         <para>
52             Some renderers (like the HTML renderer) also have support for a
53             'markup' parameter. This replaces the 'start' and 'end' parameters, and
54             it renders the markups including some default attributes and the
55             closing markup.
56         </para>
58         <sect3 id="zend.markup.renderers.add.callback">
59             <title>Add a callback markup</title>
61             <para>
62                 By adding a callback markup, you can do a lot more then just a
63                 simple replace of the markups. For instance, you can change the
64                 contents, use the parameters to influence the output etc.
65             </para>
67             <para>
68                 A callback is a class that implements the
69                 <classname>Zend_Markup_Renderer_TokenInterface</classname>
70                 interface. An example of a callback class:
71             </para>
73             <programlisting language="php"><![CDATA[
74 class My_Markup_Renderer_Html_Upper implements Zend_Markup_Renderer_TokenConverterInterface
77     public function convert(Zend_Markup_Token $token, $text)
78     {
79         return '!up!' . strtoupper($text) . '!up!';
80     }
83 ]]></programlisting>
85             <para>
86                 Now you can add the 'upper' markup, with as callback, an instance
87                 of the <classname>My_Markup_Renderer_Html_Upper</classname>
88                 class. A simple example:
89             </para>
91             <programlisting language="php"><![CDATA[
92 // Creates instance of Zend_Markup_Renderer_Html,
93 // with Zend_Markup_Parser_BbCode as its parser
94 $bbcode = Zend_Markup::factory('Bbcode');
96 // this will create a simple 'foo' markup
97 // The first parameter defines the markup's name.
98 // The second parameter takes an integer that defines the markups type.
99 // The third parameter is an array that defines other things about a
100 // markup, like the markup's group, and (in this case) a start and end markup.
101 $bbcode->addMarkup(
102     'upper',
103     Zend_Markup_Renderer_RendererAbstract::TYPE_REPLACE,
104     array(
105         'callback' => new My_Markup_Renderer_Html_Upper(),
106         'group'    => 'inline'
107     )
110 // now, this will output: 'my !up!MARKUP!up!'
111 echo $bbcode->render('my [upper]markup[/upper]');
112 ]]></programlisting>
113         </sect3>
114     </sect2>
116     <sect2 id="zend.markup.renderers.list">
117         <title>List of markups</title>
119         <table id="zend.markup.renderers.list.markups">
120             <title>List of markups</title>
122             <tgroup cols="2" align="left" colsep="1" rowsep="1">
123                 <thead>
124                     <row>
125                         <entry>Sample input (bbcode)</entry>
126                         <entry>Sample output</entry>
127                     </row>
128                 </thead>
130                 <tbody>
131                     <row>
132                         <entry>[b]foo[/b]</entry>
133                         <entry><![CDATA[<strong>foo</strong>]]></entry>
134                     </row>
136                     <row>
137                         <entry>[i]foo[/i]</entry>
138                         <entry><![CDATA[<em>foo</em>]]></entry>
139                     </row>
141                     <row>
142                         <entry>[cite]foo[/cite]</entry>
143                         <entry><![CDATA[<cite>foo</cite>]]></entry>
144                     </row>
146                     <row>
147                         <entry>[del]foo[/del]</entry>
148                         <entry><![CDATA[<del>foo</del>]]></entry>
149                     </row>
151                     <row>
152                         <entry>[ins]foo[/ins]</entry>
153                         <entry><![CDATA[<ins>foo</ins>]]></entry>
154                     </row>
156                     <row>
157                         <entry>[sup]foo[/sup]</entry>
158                         <entry><![CDATA[<sup>foo</sup>]]></entry>
159                     </row>
161                     <row>
162                         <entry>[sub]foo[/sub]</entry>
163                         <entry><![CDATA[<sub>foo</sub>]]></entry>
164                     </row>
166                     <row>
167                         <entry>[span]foo[/span]</entry>
168                         <entry><![CDATA[<span>foo</span>]]></entry>
169                     </row>
171                     <row>
172                         <entry>[acronym title="PHP Hypertext Preprocessor]PHP[/acronym]</entry>
174                         <entry>
175                             <![CDATA[<acronym title="PHP Hypertext Preprocessor">PHP</acronym>]]>
176                         </entry>
177                     </row>
179                     <row>
180                         <entry>[url=http://framework.zend.com/]Zend Framework[/url]</entry>
182                         <entry>
183                             <![CDATA[<a href="http://framework.zend.com/">Zend Framework</a>]]>
184                         </entry>
185                     </row>
187                     <row>
188                         <entry>[h1]foobar[/h1]</entry>
189                         <entry><![CDATA[<h1>foobar</h1>]]></entry>
190                     </row>
192                     <row>
193                         <entry>[img]http://framework.zend.com/images/logo.gif[/img]</entry>
195                         <entry>
196                             <![CDATA[<img src="http://framework.zend.com/images/logo.gif" />]]>
197                         </entry>
198                     </row>
199                 </tbody>
200             </tgroup>
201         </table>
202     </sect2>
203 </sect1>