1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.markup.renderers">
4 <title>Zend_Markup Renderers</title>
7 <classname>Zend_Markup</classname> is currently shipped with one renderer, the
8 <acronym>HTML</acronym> renderer.
11 <sect2 id="zend.markup.renderers.add">
12 <title>Adding your own markups</title>
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:
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.
33 Zend_Markup_Renderer_RendererAbstract::TYPE_REPLACE,
41 // now, this will output: 'my -bar-markup-baz-'
42 echo $bbcode->render('my [foo]markup[/foo]');
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.
52 Some renderers (like the <acronym>HTML</acronym> 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
58 <sect3 id="zend.markup.renderers.add.callback">
59 <title>Add a callback markup</title>
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.
68 A callback is a class that implements the
69 <classname>Zend_Markup_Renderer_TokenInterface</classname>
70 interface. An example of a callback class:
73 <programlisting language="php"><![CDATA[
74 class My_Markup_Renderer_Html_Upper
75 implements Zend_Markup_Renderer_TokenConverterInterface
78 public function convert(Zend_Markup_Token $token, $text)
80 return '!up!' . strtoupper($text) . '!up!';
87 Now you can add the 'upper' markup, with as callback, an instance
88 of the <classname>My_Markup_Renderer_Html_Upper</classname>
89 class. A simple example:
92 <programlisting language="php"><![CDATA[
93 // Creates instance of Zend_Markup_Renderer_Html,
94 // with Zend_Markup_Parser_BbCode as its parser
95 $bbcode = Zend_Markup::factory('Bbcode');
97 // this will create a simple 'foo' markup
98 // The first parameter defines the markup's name.
99 // The second parameter takes an integer that defines the markups type.
100 // The third parameter is an array that defines other things about a
101 // markup, like the markup's group, and (in this case) a start and end markup.
104 Zend_Markup_Renderer_RendererAbstract::TYPE_REPLACE,
106 'callback' => new My_Markup_Renderer_Html_Upper(),
111 // now, this will output: 'my !up!MARKUP!up!'
112 echo $bbcode->render('my [upper]markup[/upper]');
117 <sect2 id="zend.markup.renderers.list">
118 <title>List of markups</title>
120 <table id="zend.markup.renderers.list.markups">
121 <title>List of markups</title>
123 <tgroup cols="2" align="left" colsep="1" rowsep="1">
126 <entry>Sample input (bbcode)</entry>
127 <entry>Sample output</entry>
133 <entry>[b]foo[/b]</entry>
134 <entry><![CDATA[<strong>foo</strong>]]></entry>
138 <entry>[i]foo[/i]</entry>
139 <entry><![CDATA[<em>foo</em>]]></entry>
143 <entry>[cite]foo[/cite]</entry>
144 <entry><![CDATA[<cite>foo</cite>]]></entry>
148 <entry>[del]foo[/del]</entry>
149 <entry><![CDATA[<del>foo</del>]]></entry>
153 <entry>[ins]foo[/ins]</entry>
154 <entry><![CDATA[<ins>foo</ins>]]></entry>
158 <entry>[sup]foo[/sup]</entry>
159 <entry><![CDATA[<sup>foo</sup>]]></entry>
163 <entry>[sub]foo[/sub]</entry>
164 <entry><![CDATA[<sub>foo</sub>]]></entry>
168 <entry>[span]foo[/span]</entry>
169 <entry><![CDATA[<span>foo</span>]]></entry>
173 <entry>[acronym title="PHP Hypertext Preprocessor]PHP[/acronym]</entry>
176 <![CDATA[<acronym title="PHP Hypertext Preprocessor">PHP</acronym>]]>
181 <entry>[url=http://framework.zend.com/]Zend Framework[/url]</entry>
184 <![CDATA[<a href="http://framework.zend.com/">Zend Framework</a>]]>
189 <entry>[h1]foobar[/h1]</entry>
190 <entry><![CDATA[<h1>foobar</h1>]]></entry>
194 <entry>[img]http://framework.zend.com/images/logo.gif[/img]</entry>
197 <![CDATA[<img src="http://framework.zend.com/images/logo.gif" />]]>